小编ton*_*nix的帖子

如何重置emacs以utf-8-unix字符编码保存文件?

我有个问题.我发现emacs最近停止使用默认字符集" utf-8-unix " 保存所有新文件.我不明白我做了什么,但是当我打开一个文件时,在迷你缓冲区上面我看到" - :---"而不是" -U:--- ",其中"U"表示该文件用utf-8-unix charset保存.如何重置emacs以在正确的编码系统中保存文件?

linux emacs encoding utf-8

6
推荐指数
1
解决办法
5143
查看次数

如何将$ _SESSION变量传递给websocket服务器?

我在网上搜索了很多,但没有找到有用的线索.

我有一个websocket服务器和一个在我的本地机器上一起运行的Web服务器.

当客户端使用浏览器API'new WebSocket("ws:// localhost")'连接到它时,我需要将$ _SESSION数据传递给websocket服务器(请求使用反向代理发送到websocket,后者知道它当收到带有"升级"标题的请求时.

关键是客户端成功连接到ws服务器,但我还需要使用HTTP Web服务器设置的$ _SESSION变量来恢复其SESSION数据.

其实我的情况是这样的(我正在使用Ratchet库):

use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use MyApp\MyAppClassChat;

require dirname(__DIR__) . '/vendor/autoload.php';

$server = IoServer::factory(new HttpServer(new WsServer(new MyAppClass())), 8080);
$server->run();
Run Code Online (Sandbox Code Playgroud)

MyAppClass非常简单:

 <?php
namespace MyAppClass;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class MyAppClass implements MessageComponentInterface {

    protected $clients;

    public function __construct() {
        $this->clients = new \SplObjectStorage;
    }

    public function onOpen(ConnectionInterface $conn) {
            /* I would like to put recover the session infos of the clients here
               but the session_start() call returns an empty …
Run Code Online (Sandbox Code Playgroud)

php apache session websocket

6
推荐指数
1
解决办法
7308
查看次数

PCRE PHP具体的"S"(模式的额外分析)修饰符的用法和实用程序示例?

PHP手册在http://php.net/manual/en/reference.pcre.pattern.modifiers.php上说明了关于PCRE的"S"(模式的额外分析)修饰符的以下内容

小号

当一个模式将被多次使用时,值得花更多时间分析它以加快匹配所需的时间.如果设置了此修改器,则执行此额外分析.目前,研究模式仅对于没有单个固定起始字符的非锚定模式有用.

因此它的用法与应该多次使用的模式有关,没有锚点在它们内部(例如^,$)或固定的起始字符序列,例如在类似的模式中'/^abc/'.

但是没有任何具体细节,例如应用此修饰符以及它实际如何工作.

它是否仅适用于当前执行脚本的PHP线程,并且在执行脚本后,模式的"缓存"分析会丢失?或者引擎是否将模式的分析存储在全局缓存中,然后使用PCRE并使用带有此修饰符的模式的几个PHP线程可以使用该缓存?

另外,从PCRE介绍:http://php.net/manual/en/intro.pcre.php

注意:此扩展维护已编译正则表达式的全局每线程缓存(最多4096)

如果仅为每个线程使用"S"修饰符,它与编译的正则表达式的PCRE高速缓存有何不同?我想存储了额外的信息,就像MySQL在索引表中的行时那样(当然在PCRE的情况下,这些附加信息存储在内存中).

最后,但并非最不重要的是,有人经历过一个真实的用例,他/她使用过这个修饰符,你是否注意到了改进并欣赏它的好处?

感谢您的关注.

php regex caching pcre

6
推荐指数
1
解决办法
286
查看次数

在插入过程中逐步存储从根节点到多路树的节点的路径,因此存储操作不会具有O(n)的复杂度

我想问一问,在插入新节点期间,是否有人知道一种存储从根节点到多路树的新节点的路径的有效方法。例如,如果我有以下树:

多路树

对于每个节点,我目前通过以下方式存储从根节点到根节点的路径的数组,方法是通过int为每个深度相同的子代分配一个唯一的ID:

Root node -> [1]

Depth 1, child 1 of root -> [1, 1]
Depth 1, child 2 of root -> [1, 2]

Depth 2, child 1 of parent 1 -> [1, 1, 1]
Depth 2, child 2 of parent 1 -> [1, 1, 2]
Depth 2, child 3 of parent 1 -> [1, 1, 3]
Depth 2, child 1 of parent 2 -> [1, 2, 4]
Depth 2, child 2 of parent 2 -> [1, 2, …
Run Code Online (Sandbox Code Playgroud)

algorithm tree multiway-tree treepath

6
推荐指数
1
解决办法
103
查看次数

在 Linux Foundation/Foundation.h 链接上使用 clang 编译目标 C:找不到文件

我正在尝试在 Ubuntu 上用 Objective C 编译程序,我已经安装了 GNUstep,设置了所有GNUSTEP_*环境变量,并安装了 clang,因为我读到 gcc 无法编译带有块的 Objective-C 代码(Objective-C 'anonymous ' 函数,只是要清楚:) ^ { }

当我运行这个命令时我得到了什么: clang hello.m -o hello

是:

hello.m:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
        ^
1 error generated.
Run Code Online (Sandbox Code Playgroud)

我也试过这个: clang -L '/usr/include/GNUstep/Foundation/Foundation.h' hello.m -o hello

/usr/include/...我的系统上Foundation.h文件的路径在哪里;但我仍然得到相同的结果。

如何自动链接这些头文件并编译 Objective-C?

谢谢!

compilation objective-c clang gnustep

5
推荐指数
1
解决办法
3970
查看次数

如何在 android 中使用 autocompleteTextView 执行 Trie 搜索?

我需要使用 Trie 搜索来实现 AutocompleteTextView。我正在使用一个 Vertex 类和一个 Trie 类作为 Trie 树数据结构,以及一个用于自定义 autocompleteTextView 下拉框视图的适配器。

以下是我正在使用的所有类:

顶点类:

public class Vertex {

private HashMap<Character, Vertex> vertexSons;
private List<Integer> wordsIndexList;
private List<Integer> prefixesIndexList;
private int wordsNumber;
private int prefixesNumber;

public Vertex() {
    vertexSons = new HashMap<Character, Vertex>();
    wordsIndexList = new ArrayList<Integer>();
    prefixesIndexList = new ArrayList<Integer>();
    wordsNumber = 0;
    prefixesNumber = 0;
}

public boolean hasWords() {
    if (wordsNumber > 0) {
        return true;
    }
    return false;
}

public boolean hasPrefixes() {
    if (prefixesNumber > 0) …
Run Code Online (Sandbox Code Playgroud)

java android trie autocompletetextview

5
推荐指数
1
解决办法
3278
查看次数

JavaScript RegExps中'y'粘滞模式修饰符的用途是什么?

MDN为JavaScript RegExp引入了'y'粘性标志.这是一个文档摘录:

ÿ

黏; 仅匹配目标字符串中此正则表达式的lastIndex属性指示的索引(并且不会尝试与任何后续索引匹配).

还有一个例子:

var text = 'First line\nSecond line';
var regex = /(\S+) line\n?/y;

var match = regex.exec(text);
console.log(match[1]);        // prints 'First'
console.log(regex.lastIndex); // prints '11'

var match2 = regex.exec(text);
console.log(match2[1]);       // prints 'Second'
console.log(regex.lastIndex); // prints '22'

var match3 = regex.exec(text);
console.log(match3 === null); // prints 'true'
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,g全局标志的使用实际上没有任何区别:

var text = 'First line\nSecond line';
var regex = /(\S+) line\n?/g;

var match = regex.exec(text);
console.log(match[1]);        // prints 'First'
console.log(regex.lastIndex); // prints '11'

var …
Run Code Online (Sandbox Code Playgroud)

javascript regex

5
推荐指数
1
解决办法
1131
查看次数

PHP PDO MySQL以及它如何真正处理MySQL事务?

我试图克服它,但我无法理解使用PDO和MySQL在PHP中进行事务处理的逻辑.

我知道这个问题会很长,但我认为这是值得的.

鉴于我阅读了很多关于MySQL事务的信息,服务器如何处理它们,它们与锁和其他隐式提交语句的关系等等,不仅在SO上,而且在MySQL和PHP手册上:

并给出此代码:

模式:

CREATE TABLE table_name (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  table_col VARCHAR(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `another_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `another_col` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Run Code Online (Sandbox Code Playgroud)

test1.php(with PDO::setAttribute(PDO::ATTR_AUTOCOMMIT, 0)):

<?php

// PDO
define('DB_HOST', 'localhost');
define('DB_USER', 'user');
define('DB_PASS', 'password');
define('DB_NAME', 'db_name');

/**
 * Uses `$this->pdo->setAttribute(PDO::ATTR_AUTOCOMMIT,0);`
 */
class …
Run Code Online (Sandbox Code Playgroud)

php mysql pdo locking transactions

5
推荐指数
1
解决办法
556
查看次数

React JS 中的 value 和 defaultValue 之间的真正区别是什么?

在 React 的主页上,有最后一个示例使用外部插件的组件),带有textarea

    <textarea
      id="markdown-content"
      onChange={this.handleChange}
      defaultValue={this.state.value}
    />
Run Code Online (Sandbox Code Playgroud)

当我输入时,textarea会更新。

现在,我试图改变defaultValuevalue

    <textarea
      id="markdown-content"
      onChange={this.handleChange}
      value={this.state.value}
    />
Run Code Online (Sandbox Code Playgroud)

结果是相同的(与 一样defaultValue,即当我输入时,textarea更新后的文本会在视觉上得到更新)。

那么,两者之间的真正区别是什么?

javascript reactjs

5
推荐指数
2
解决办法
1471
查看次数

Python Matplotlib顺时针饼图

我在玩Python及其matplotlib库,如何创建以下图表,以使第一个切片从顶部开始并向右(顺时针)移动,而不是向左(逆时针)移动:

在此处输入图片说明

码:

import matplotlib.pyplot as plt
import re
import math

# The slices will be ordered and plotted counter-clockwise if startangle=90.
sizes = [175, 50, 25, 50]
total = sum(sizes)
print('TOTAL:')
print(total)
print('')
percentages = list(map(lambda x: str((x/(total * 1.00)) * 100) + '%', sizes))

print('PERCENTAGES:')
print(percentages)
backToFloat = list(map(lambda x: float(re.sub("%$", "", x)), percentages))
print('')

print('PERCENTAGES BACK TO FLOAT:')
print(backToFloat)
print('')

print('SUM OF PERCENTAGES')
print(str(sum(backToFloat)))
print('')
labels = percentages
colors = ['blue', 'red', 'green', 'orange']
patches, texts …
Run Code Online (Sandbox Code Playgroud)

python matplotlib pie-chart

4
推荐指数
1
解决办法
1442
查看次数