到目前为止,我一直在使用find-and-replace操作手动重构代码
%s:/stringiwanttoreplace/newstring/g
Run Code Online (Sandbox Code Playgroud)
在vim.
但是,如果我在特定目录中的许多文件中都有stringiwanttoreplace,那么这是一个缓慢且费力的过程.
我目前/典型的缓慢而费力的过程涉及到一个问题: -
grep -rn "stringiwanttoreplace" .
Run Code Online (Sandbox Code Playgroud)
在我的终端中显示stringiwanttoreplace所在的所有位置/文件名; 现在我知道哪些文件包含stringiwanttoreplace,我将逐个打开每个文件,以在每个文件中执行查找和替换操作.
是否有更高效的工作流程(在vim中)来完成这项工作?
澄清:我更喜欢基于vim的解决方案,而不是bash脚本/单行.
这是在python中对给定密码进行盐析和散列的示例.
import scrypt
import os
# Length of salt
PW_SALT_BYTES = 32
# Length of scrypt hash of passwords
PW_HASH_BYTES = 64
# test password
password = "hello"
salt = os.urandom(PW_SALT_BYTES).encode('hex')
# hash(password, salt, N=1 << 14, r=8, p=1, buflen=64)
hashed_password = scrypt.hash(str(password), salt.decode('hex'), buflen=PW_HASH_BYTES).encode('hex')
print(hashed_password)
Run Code Online (Sandbox Code Playgroud)
哪个会给我们一个哈希和盐渍的字符串作为回报: -
4d1da45b401961fccb10e094ecd70ec79510f05483ca293d300bbd0024e35866ca39fe09fbc15f83a359431021a1ed9644f7d2b871b357e37a186300877edb18
Run Code Online (Sandbox Code Playgroud)
我将如何在golang中实现这一点?
所以我试图从源代码git://github.com/twitter/bootstrap.git"构建"twitter bootstrap,然后我将它克隆到我的本地机器上.
显然,在我的本地机器上,我安装了nodejs和npm,并且安装了所需的节点包和uglify-js.并且所有节点模块都在我的系统路径中,因此我的终端中可以使用"lessc"和"uglifyjs"命令.
进入bootstrap的根目录,我运行"make",这是输出: -
(luc)calvins-MacBook.local ttys002 Fri Feb 03 10:51:29 |~/work/luc/static/bootstrap|
calvin$ make
mkdir -p bootstrap/img
mkdir -p bootstrap/css
mkdir -p bootstrap/js
cp img/* bootstrap/img/
lessc ./less/bootstrap.less > bootstrap/css/bootstrap.css
lessc --compress ./less/bootstrap.less > bootstrap/css/bootstrap.min.css
lessc ./less/responsive.less > bootstrap/css/bootstrap.responsive
lessc --compress ./less/responsive.less > bootstrap/css/bootstrap.min.responsive
cat js/bootstrap-transition.js js/bootstrap-alert.js js/bootstrap-button.js js/bootstrap-carousel.js js/bootstrap-collapse.js js/bootstrap-dropdown.js js/bootstrap-modal.js js/bootstrap-tooltip.js js/bootstrap-popover.js js/bootstrap-scrollspy.js js/bootstrap-tab.js js/bootstrap-typeahead.js > bootstrap/js/bootstrap.js
uglifyjs -nc bootstrap/js/bootstrap.js > bootstrap/js/bootstrap.min.js
zip -r docs/assets/bootstrap.zip bootstrap
updating: bootstrap/ (stored 0%)
updating: bootstrap/css/ (stored 0%)
updating: bootstrap/css/bootstrap.css (deflated 85%) …Run Code Online (Sandbox Code Playgroud) 所以我在R中有一个spatialpolygons对象; 但我不确定为什么我无法从中检索"区域"槽.
这是我的R会议:
> spatialpolygons
An object of class "SpatialPolygons"
Slot "polygons":
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 20.50516 57.72918
Slot "area":
[1] 36.85484
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 16.48438 59.73633
[2,] 22.59277 61.14258
[3,] 24.74609 55.03418
[4,] 17.49512 55.12207
[5,] 16.48438 59.73633
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] 20.50516 57.72918
Slot "ID":
[1] "myMultiPolygons"
Slot "area":
[1] 36.85484
Slot …Run Code Online (Sandbox Code Playgroud) 我在使用pip编译使用pip的默认clang编译器编译mapscript(是包含C代码的pypi的包)时遇到了一些麻烦.
这是我的尝试: -
$ sudo pip install mapscript
Password:
Downloading/unpacking mapscript
Running setup.py egg_info for package mapscript
Requirement already satisfied (use --upgrade to upgrade): distribute in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from mapscript)
Installing collected packages: mapscript
Running setup.py install for mapscript
building '_mapscript' extension
/opt/local/bin/gcc-apple-4.2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/include -I/opt/local/include -I/opt/local/include -pipe -O2 -arch x86_64 -fPIC -Wall -DNEED_NONBLOCKING_STDERR -DHAVE_VSNPRINTF -DNEED_STRRSTR -DNEED_NONBLOCKING_STDERR -DUSE_WMS_SVR -DUSE_GDAL -DUSE_OGR -DUSE_PROJ -DUSE_EPPL -DUSE_GD_GIF -DUSE_GD_PNG -DUSE_GD_JPEG -DUSE_GD_WBMP -DUSE_GD_FT -DGD_HAS_FTEX_XSHOW -DGD_HAS_GDIMAGEGIFPTR -DGD_HAS_GETBITMAPFONTS -DUSE_ICONV -DUSE_ZLIB -I/opt/local/include -I/opt/local/include -I/opt/local/include -DHAVE_VSNPRINTF …Run Code Online (Sandbox Code Playgroud) 参考 - http://docs.python.org/library/unittest.html#assert-methods
assertEqual(a, b) # checks that a == b
assertIs(a, b) # checks that a is b <---- whatever that means????
Run Code Online (Sandbox Code Playgroud) 在macports上,有一个名为postgresql_select的包
这是作为一个实用程序来选择postgresql的当前活动版本(假设我的Mac上安装了多个版本的postgresql)?如果是这样,我该如何使用它?
pip install --upgrade -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
重复所有以前安装的依赖项的安装过程,当我有一个巨大的依赖项列表(比如30多个?)时可能会很痛苦.
是否有办法检查更新的requirements.txt并仅安装自上次安装尝试以来已包含在requirements.txt文件中的特定依赖项?
我发现这是pip的一个真正的缺点(或者在virtualenv中使用pip).不喜欢pip的重复安装性质.
django guardian https://github.com/lukaszb/django-guardian是一个写得很好的对象级权限应用程序; 我实际上已经阅读并在各种django项目中使用了相当多的其他django对象级权限应用程序.
在我最近的一个项目中,我决定使用django监护人,但我有一个模型设计问题,涉及两种可能方法的优缺点及其对sql查询性能的各自影响: -
使用django.contrib.auth.models.Group并扩展到我的自定义组织应用程序的模型; 要么
使用django.contrib.auth.models.User而不是为我的组织应用程序中的每个组织类型创建一个m2m字段.
方法#1
# Organisation app's models.py
from django.contrib.auth.models import Group
class StudentClass(models.Model):
name = models.CharField('Class Name', max_length=255)
groups = models.ManyToManyField(Group, blank=True)
size = models.IntegerField('Class Size', blank=True)
class SpecialInterestGroup(models.Model):
name = models.CharField('Interest Group Name', max_length=255)
groups = models.ManyToManyField(Group, blank=True)
description = models.TextField('What our group does!', blank=True)
class TeachingTeam(models.Model):
name = models.CharField('Teacher Team Name', max_length=255)
groups = models.ManyToManyField(Group, blank=True)
specialization = models.TextField('Specialty subject matter', blank=True)
Run Code Online (Sandbox Code Playgroud)
在这种方法中,当第一次将用户添加到组(django组)时,创建组对象并将其分配给这3个类中的一个,如果该组对象尚未属于该类,则添加成.
这意味着每个StudentClass对象, …
我是Golang的新手,目前正在关注本教程和源代码 - http://golang.org/doc/articles/wiki/part2.go
构建此文件后,我得到了
calvin$ ./mywebwiki2
2012/07/23 17:12:59 http: panic serving [::1]:58820: runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/pkg/net/http/server.go:576 (0x3f202)
_func_003: buf.Write(debug.Stack())
/private/tmp/bindist454984655/go/src/pkg/runtime/proc.c:1443 (0x10c79)
/private/tmp/bindist454984655/go/src/pkg/runtime/runtime.c:128 (0x11745)
/private/tmp/bindist454984655/go/src/pkg/runtime/thread_darwin.c:418 (0x148b5)
/Users/calvin/work/gowiki/mywebwiki2.go:33 (0x2248)
viewHandler: fmt.Fprintf(w, "<h1>%s</h1><div>%s</div>", p.Title, p.Body)
/usr/local/go/src/pkg/net/http/server.go:690 (0x331ae)
HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:926 (0x34030)
(*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:656 (0x32fc1)
(*conn).serve: handler.ServeHTTP(w, w.req)
/private/tmp/bindist454984655/go/src/pkg/runtime/proc.c:271 (0xed7f)
2012/07/23 17:12:59 http: panic serving [::1]:58821: runtime error: invalid memory address or nil pointer dereference
Run Code Online (Sandbox Code Playgroud)
知道我做错了导致这种明显的内存损坏吗?