Skip to content

Instantly share code, notes, and snippets.

View International's full-sized avatar
🪲
Debugging

George Opritescu International

🪲
Debugging
View GitHub Profile
@International
International / subproccess_example.py
Created September 9, 2011 12:06
python subprocess pid/kill example
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
@International
International / gist:4143352
Created November 25, 2012 12:44
sample iteration C++
#include <iostream>
using namespace std;
int main(int argc,char* argv[]) {
for(int i = 0;i < 5;i++) {
cout << "Hello world!" << endl;
}
return 0;
}
@International
International / gist:4143355
Created November 25, 2012 12:46
java sample iteration
public class SampleIteration {
public static void main(String[] args) {
for(int i = 0;i < 5;i++) {
System.out.println("Hello world");
}
}
}
@International
International / gist:4143361
Created November 25, 2012 12:48
ruby sample iteration
5.times { puts "Hello world" }
# Rails 3
"police".singularize
=> "polouse"
# Rails 4
"police".singularize
=> "police"
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.
class SomeBackgroundOperation
def run
# code to run in the background goes here
end
end
# enqueing it to run
Rails.queue.push(SomeBackgroundOperation.new)
# config/environments/production.rb
# background thread
config.queue = ActiveSupport::Queue
# sidekiq ( rails4 branch )
config.queue = Sidekiq::Client::Queue
# make all mailers async
config.action_mailer.async = true
# make only a specific mailer async
class SomeMailer < ActionMailer::Base
self.async = true
end
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