This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import time | |
import sys | |
if __name__ == "__main__": | |
if len(sys.argv) != 2: | |
exit("need an argument") | |
to_run = sys.argv[1] | |
proc = subprocess.Popen(to_run) | |
print "start process with pid %s" % proc.pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(int argc,char* argv[]) { | |
for(int i = 0;i < 5;i++) { | |
cout << "Hello world!" << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleIteration { | |
public static void main(String[] args) { | |
for(int i = 0;i < 5;i++) { | |
System.out.println("Hello world"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5.times { puts "Hello world" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails 3 | |
"police".singularize | |
=> "polouse" | |
# Rails 4 | |
"police".singularize | |
=> "police" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PeopleController < ActionController::Base | |
# This will raise an ActiveModel::ForbiddenAttributes exception because it's using mass assignment | |
# without an explicit permit step. | |
def create | |
Person.create(params[:person]) | |
end | |
# This will pass with flying colors as long as there's a person key in the parameters, otherwise | |
# it'll raise a ActionController::MissingParameter exception, which will get caught by | |
# ActionController::Base and turned into that 400 Bad Request reply. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeBackgroundOperation | |
def run | |
# code to run in the background goes here | |
end | |
end | |
# enqueing it to run | |
Rails.queue.push(SomeBackgroundOperation.new) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/environments/production.rb | |
# background thread | |
config.queue = ActiveSupport::Queue | |
# sidekiq ( rails4 branch ) | |
config.queue = Sidekiq::Client::Queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make all mailers async | |
config.action_mailer.async = true | |
# make only a specific mailer async | |
class SomeMailer < ActionMailer::Base | |
self.async = true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyController < ActionController::Base | |
include ActionController::Live | |
def stream | |
response.headers['Content-Type'] = 'text/event-stream' | |
100.times { | |
response.stream.write "hello world\n" | |
sleep 1 | |
} | |
response.stream.close |
OlderNewer