我想在GitHub上放置一个Git项目,但它包含某些带有敏感数据的文件(用户名和密码,比如/ config/deploy.rb for capistrano).
我知道我可以将这些文件名添加到.gitignore,但这不会删除他们在Git中的历史记录.
我也不想通过删除/.git目录重新开始.
有没有办法删除Git历史记录中特定文件的所有痕迹?
我是否可以在ActiveRecord,Ruby on Rails中创建和使用包含no :id列的数据库表.
我不仅要忽略id列,而且希望它绝对不存在.
Table Example
:key_column :value_column
0cc175b9c0f1b6a831c399e269772661 0cc175b9c0f1b6a831c399e269772661
4a8a08f09d37b73795649038408b5f33 0d61f8370cad1d412f80b84d143e1257
92eb5ffee6ae2fec3ad71c777531578f 9d5ed678fe57bcca610140957afab571
Run Code Online (Sandbox Code Playgroud)
任何更多信息(如:id_column)都会破坏整个功能.
我如何在rails中实现这样的东西?
当创建一个新的资源,它需要做一些冗长的处理前的资源准备好了,我怎么发送处理掉到背景的地方也不会撑起当前请求或其他流量到我的web应用程序?
在我的模型中:
class User < ActiveRecord::Base
after_save :background_check
protected
def background_check
# check through a list of 10000000000001 mil different
# databases that takes approx one hour :)
if( check_for_record_in_www( self.username ) )
# code that is run after the 1 hour process is finished.
user.update_attribute( :has_record )
end
end
end
Run Code Online (Sandbox Code Playgroud) 在不使用库的情况下,使用css选择器查找Dom元素的最简单方法是什么?
function select( selector ) {
return [ /* some magic here please :) */ ]
};
select('body')[0] // body;
select('.foo' ) // [div,td,div,a]
select('a[rel=ajax]') // [a,a,a,a]
Run Code Online (Sandbox Code Playgroud)
这个问题纯粹是学术性的.我有兴趣了解这是如何实现的以及"障碍"是什么.这个函数的预期行为是什么?(返回数组,或返回第一个Dom元素等).
我有一个饲料控制器,永远不会返回304.
我的渲染调用看起来像这样(json_feed_contentjsonp字符串在哪里);
render :text => jsonp_feed_content, :content_type => "application/json"
Run Code Online (Sandbox Code Playgroud)
我在生产环境中将缓存设置为false:
config.action_controller.perform_caching = false
Run Code Online (Sandbox Code Playgroud)
我有一个客户端脚本,不断轮询此Feed中的内容,但大多数请求返回304[Content Not Changed].有没有办法防止我的rails应用程序这样做?
我需要监控我的音频线路输入在Linux中,并在音频播放时,声音必须被记录并保存到一个文件中.与运动如何监控视频输入类似.
是否有可能用bash做到这一点?类似的东西:
#!/bin/bash
# audio device
device=/dev/audio-line-in
# below this threshold audio will not be recorded.
noise_threshold=10
# folder where recordings are stored
storage_folder=~/recordings
# run indefenitly, until Ctrl-C is pressed
while true; do
# noise_level() represents a function to determine
# the noise level from device
if noise_level( $device ) > $noise_threshold; then
# stream from device to file, can be encoded to mp3 later.
cat $device > $storage_folder/$(date +%FT%T).raw
fi;
done;
Run Code Online (Sandbox Code Playgroud)
编辑:我想从这个程序中获得的流程是
a. when …Run Code Online (Sandbox Code Playgroud) 如果我必须在我的开发分支上关注文件:
# file.rb
class Code
def methodA
'aA1'
end
def methodB
'bB2'
end
end
Run Code Online (Sandbox Code Playgroud)
但在我的主分支上,我想将方法分成不同的文件:
# in file.rb
class Code
def methodA
'aA1'
end
end
# in extra.rb
class Code
def methodB
'bB2'
end
end
Run Code Online (Sandbox Code Playgroud)
我可以简单地在开发时创建文件,然后签出以掌握,重新定位并手动分离文件,但是是否可以进行设置以便当我对开发进行更改时它将被转移到文件的右侧"部分"在主人?
请考虑以下情形.
我有一系列数字:
[ 1,2,3,4 ]
Run Code Online (Sandbox Code Playgroud)
如果加入这个数组,我的数字是1234.
我想交换数字来实现最接近的数字.
1234将成为1243,这将成为1324,这将成为1342等等.
我需要使用什么算法在数组中进行此更改?
理想情况下,我想以这种方式使用该算法:(假设Array将此算法作为一个称为演练的函数)
[ 1,2,3,4].walkthrough() # gives [ 1, 2, 4, 3 ]
[ 1,2,4,3].walkthrough() # gives [ 1, 3, 2, 4 ]
Run Code Online (Sandbox Code Playgroud)
数字列表继续:
1234
1243
1324
1342
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
我有一个脚本应该在我的本地机器上模仿ffmpeg,通过将命令发送到远程机器,在那里运行然后返回结果.(参见前面的堆栈溢出问题.)
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'net/sftp'
require 'highline/import'
file = ARGV[ ARGV.index( '-i' ) + 1] if ARGV.include?( '-i' )
puts 'No input file specified' unless file;
host = "10.0.0.10"
user = "user"
prod = "new-#{file}" # product filename (call it <file>-new)
rpath = "/home/#{user}/.rffmpeg" # remote computer operating directory
rfile = "#{rpath}/#{file}" # remote filename
rprod = "#{rpath}/#{prod}" # remote product
cmd = "ffmpeg -i #{rfile} #{rprod}"# remote command, constructed
pass …Run Code Online (Sandbox Code Playgroud) Chrome在加载时间期间或之后错误地报告图像的宽度和高度值.在此代码示例中使用了Jquery:
<img id='image01' alt='picture that is 145x134' src='/images/picture.jpg' />
<script>
var img = $( 'img#image01' )
img.width() // would return 145 in Firefox and 0 in Chrome.
img.height() // would return 134 in Firefox and 0 in Chrome.
</script>
Run Code Online (Sandbox Code Playgroud)
如果将脚本放在$(function(){})函数中,结果是相同的.但如果您在页面加载后几秒钟运行代码,则chrome会返回正确的结果.
<script>
function example () {
var img = $( 'img#image01' );
img.width() // returns 145 in both Firefox and Chrome.
img.height() // returns 134 in both Firefox and Chrome. …Run Code Online (Sandbox Code Playgroud) 我正在寻找与以下Ruby代码等效的Delphi
if Time.now.hour > 12 then
# Statement;
else
# Alternative Statement;
end
Run Code Online (Sandbox Code Playgroud)
谢谢Stefan
我如何使用正则表达式拆分此字符串:
string = "a[a=d b&c[e[100&2=34]]] e[cheese=blue and white] x[a=a b]"
Run Code Online (Sandbox Code Playgroud)
进入这个数组:
string.split( regexp ) =>
[ "a[a=d b&c[e[100&2=34]]]", "e[cheese=blue and white]", "x[a=a b]" ]
Run Code Online (Sandbox Code Playgroud)
的基本规则是,串应当在被分割空白(\ S) ,除非空白内部存在括号([]) ;
javascript ×4
ruby ×3
git ×2
activerecord ×1
algorithm ×1
arrays ×1
audio ×1
bash ×1
command-line ×1
datetime ×1
delphi ×1
dom ×1
git-commit ×1
html ×1
jquery ×1
linux ×1
mysql ×1
permutation ×1
regex ×1
security ×1
ssh ×1