在react组件中,首选在constructor()或componentWillMount()中设置初始状态?
export default class MyComponent extends React.Component{
constructor(props){
super(props);
this.setState({key: value});
}
}
Run Code Online (Sandbox Code Playgroud)
要么
export default class MyComponent extends React.Component{
componentWillMount(props){
this.setState({key: value});
}
}
Run Code Online (Sandbox Code Playgroud) 我有一堆以"-e"结尾的文件要删除.
$ find . -name "*-e" exec rm {} \;
find: exec: unknown primary or operator
Run Code Online (Sandbox Code Playgroud)
正则表达式是否以某种方式扩展,将一切都搞砸了?
似乎有些autoconf项目使用configure.in文件生成configure脚本,有些则使用configure.ac.
使用其中一个或另一个有什么区别/优势?
我有这些模型,我正在尝试使用factory_girl创建工厂.
class Foo < ActiveRecord::Base
belongs_to :baz
end
class Baz < ActiveRecord::Base
has_many :foos
end
Run Code Online (Sandbox Code Playgroud)
我不知道如何创建工厂而不创建一个工厂无休止地互相呼叫的循环.
Factory.define :foo do |f|
f.after_create do |ff|
ff.baz = Factory(:baz)
end
end
Factory.define :baz do |f|
f.after_create do |ff|
ff.foos = [Factory.create(:foo)]
end
end
Run Code Online (Sandbox Code Playgroud)
我意识到我可以ff.foos = [Factory.create(:foo)]在baz工厂里闲逛,但在我的baz测试中,我被迫使用foo.baz而不是仅仅使用baz.我是否被迫在测试中将baz其从foo工厂中取出来使用该对象?或者,还有更好的方法?
我有一个长64个样本的波形.如果采样率为44100 hz,我该如何播放(循环)此波形以使其播放任意频率?
频率=样本中的采样率/波形持续时间
因此频率应为689hz(44100/64).如果我想要它,65.41hz(C-2),我必须这样做:
65.41 = 44100/x
求解x得到aprox.674.208.因此,我需要弄清楚播放波形的速度,以获得此频率.所以我们可以解决这个等式:
64*x = 674.208
得到大约10.5.因此波形需要以其原始速度的10.5%播放.
这是我的代码:
double smp_index = 0;
double freq = .105;
void callback(void *data, Uint8 *buf, int len){
int i;
s8 *out;
out = (s8*) buf;
if(smp_index < waveform_length){
for(i = 0; i < len; i ++){
out[i] = smpdata[(int)smp_index];
smp_index +=freq;
if(smp_index >= waveform_length)
smp_index = 0;
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此产生的音频应该是关于音符C-2,但它更多的是D-2.是演员
(int)smp_index
Run Code Online (Sandbox Code Playgroud)
造成这个问题?我看不到任何其他方法来实现这个目标......
有人知道可以在Windows上创建受密码保护的zip文件的C库吗?似乎已经从Windows 7中删除了使用内置zip工具密码保护zip文件的选项,但我不认为这是一个问题.
zziplib或7-Zip SDK可以这样做吗?
我无法记录来自delayed_job进程的消息.这是正在运行的工作.
class MyJob
def initialize(blahblah)
@blahblah = blahblah
@logger = Logger.new(File.join(Rails.root, 'log', 'delayed_job.log'))
end
def perform
@logger.add Logger::INFO, "logging from delayed_job"
#do stuff
end
end
Run Code Online (Sandbox Code Playgroud)
我尝试了各种日志记录级别,并且在我的环境配置中有config.log_level =:debug.我从monit运行delayed_job.我正在使用delayed_job 3.0.1和ruby 1.9.3以及rails 3.0.10.
ruby ruby-on-rails background-process delayed-job ruby-on-rails-3
尝试使用cocoapods将alamofire添加到项目中.Xcode版本:版本6.1.1(6A2008a)
Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'OAuth.io'
pod 'Alamofire', '~> 1.1'
Run Code Online (Sandbox Code Playgroud)
这是错误:
Libtool /Users/tony/Library/Developer/Xcode/DerivedData/Candytone-aynufizixrzmtwgatrvrjynlonxv/Build/Products/Debug-iphonesimulator/libPods-Alamofire.a normal x86_64
cd /Users/tony/src/candytone-ios/Candytone/Pods
export IPHONEOS_DEPLOYMENT_TARGET=8.1
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk -L/Users/tony/Library/Developer/Xcode/DerivedData/Candytone-aynufizixrzmtwgatrvrjynlonxv/Build/Products/Debug-iphonesimulator -filelist /Users/tony/Library/Developer/Xcode/DerivedData/Candytone-aynufizixrzmtwgatrvrjynlonxv/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-Alamofire.build/Objects-normal/x86_64/Pods-Alamofire.LinkFileList -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/tony/Library/Developer/Xcode/DerivedData/Candytone-aynufizixrzmtwgatrvrjynlonxv/Build/Intermediates/Pods.build/Debug-iphonesimulator/Pods-Alamofire.build/Objects-normal/x86_64/Pods_Alamofire.swiftmodule -framework Foundation -o /Users/tony/Library/Developer/Xcode/DerivedData/Candytone-aynufizixrzmtwgatrvrjynlonxv/Build/Products/Debug-iphonesimulator/libPods-Alamofire.a
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] …Run Code Online (Sandbox Code Playgroud) 我正试图在rails中调整我的will_pagniate分页.我希望旧页面淡出,新的页面淡入.
这是我的控制器的相关部分:
respond_to do |format|
format.html # new.html.erb
format.js {
render :update do |page|
page.replace 'page', :partial => 'cur_page'
end
}
format.xml { render :xml => @branch }
end
Run Code Online (Sandbox Code Playgroud)
上述部分:
<div id="page">
<%= will_paginate %>
<div id="posts">
<%= render @posts %>
</div>
<%= will_paginate %>
</div>
Run Code Online (Sandbox Code Playgroud)
和application.js的相关部分:
document.observe("dom:loaded", function() {
// the element in which we will observe all clicks and capture
// ones originating from pagination links
var container = $(document.body)
if (container) {
var img = new Image …Run Code Online (Sandbox Code Playgroud) 我正在尝试用露营制作一个简单的博客,就像野营一样,只是我想用haml来代替markaby.我想使用_post.html.haml部分渲染帖子,但我有一种感觉,我可能会以错误的方式去做.
Blog.rb
require 'camping'
Camping.goes :Blog
Blogtitle = "My Blog"
module Blog
# Path to where you want to store the templates
set :views, File.dirname(__FILE__) + '/views'
module Blog::Models
class Post < Base; belongs_to :user; end
class Comment < Base; belongs_to :user; end
class User < Base; end
end
module Blog::Controllers
class Index
def get
@posts = Post.find :all
render :index
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
意见/ index.html.haml
!!!
%html
%head
%meta{'http-equiv' => 'Content-Type', :content => 'text/html', :charset => 'UTF-8' }/ …Run Code Online (Sandbox Code Playgroud) c ×3
ruby ×3
unix ×2
ajax ×1
alamofire ×1
audio ×1
autoconf ×1
autotools ×1
bash ×1
c++ ×1
callback ×1
camping ×1
delayed-job ×1
factory-bot ×1
find ×1
haml ×1
ios ×1
iphone ×1
pagination ×1
prototypejs ×1
reactjs ×1
rm ×1
sdl ×1
swift ×1
unit-testing ×1
waveform ×1
windows ×1
windows-7 ×1
zip ×1