Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb| # ~/.config/fish/config.fish | |
| . ~/.config/fish/fish_prompt.fish | |
| set fish_greeting '' # turn off greeting | |
| function fish_title;end | |
| alias vi 'vim' |
The avconv utility can be made to work in 'the Unix way' by specifying stdin and/or stdout instead of filenames for the input and output respectively. See: http://libav.org/avconv.html#pipe
Example:
cat input.ts | avconv -i pipe:0 -f mp4 -movflags frag_keyframe pipe:1 | cat > output.mp4
Using node's require('child_process').spawn(), we can pipe streams of video data through avconv's stdin and stdout and thus Stream All The Things.
var fs = require('fs');| import contextlib | |
| import subprocess | |
| # Unix, Windows and old Macintosh end-of-line | |
| newlines = ['\n', '\r\n', '\r'] | |
| def unbuffered(proc, stream='stdout'): | |
| stream = getattr(proc, stream) | |
| with contextlib.closing(stream): | |
| while True: | |
| out = [] |
| /** | |
| * Use `Array#some` when it is convenient to exit on truthy return values | |
| * Use `lodash.forEach` when it is convenient to exit on false (you can cast if necessary with `!!`) | |
| */ | |
| var _ = require('lodash'); | |
| var numbers = [1, 2, 3, 4, 5, 6]; | |
| console.log('Array#forEach (result not as expected)'); |
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
| class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
| def facebook | |
| @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user) | |
| if @user.persisted? | |
| flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook" | |
| sign_in_and_redirect @user, :event => :authentication | |
| else | |
| session["devise.facebook_data"] = request.env["omniauth.auth"] | |
| redirect_to new_user_registration_url |
Here's a few things I tried to write output to a python subprocess pipe.
from subprocess import Popen, PIPE
p = Popen('less', stdin=PIPE)
for x in xrange(100):
p.communicate('Line number %d.\n' % x)