Skip to content

Instantly share code, notes, and snippets.

@pgr0ss
pgr0ss / keybase.md
Created Mar 14, 2014
Keybase proof
View keybase.md

Keybase proof

I hereby claim:

  • I am pgr0ss on github.
  • I am pgr0ss (https://keybase.io/pgr0ss) on keybase.
  • I have a public key whose fingerprint is 677A A3F7 3481 520F B93C 17D8 BE07 2666 70FE F87A

To claim this, I am signing this object:

View support.rb
desc "install R packages"
task :install_R_packages do
R_packages = File.read("#{release_path}/R_packages.txt").lines.map { |line| line.strip }
R_package_cmd = R_packages.map do |package|
R_package_cmd << 'if(!require(\"'+package+'\")){ install.packages(\"'+package+'\",lib=c(\"'+shared_path+'/R\"), repos=\"http://cran.cnr.berkeley.edu/\"); };'
end.join(' ')
sudo "sh -c 'if [ ! -d #{shared_path}/R ]; then mkdir #{shared_path}/R; fi'"
sudo "sh -c 'export R_LIBS_USER=#{shared_path}/R && R --vanilla -e \"#{R_package_cmd}\"'"
View mysql_deadlock.sql
CREATE TABLE foo (id INT) ENGINE INNODB;
-- session 1 session 2
------------------------------------------------------------------------
BEGIN;
------------------------------------------------------------------------
BEGIN;
------------------------------------------------------------------------
INSERT INTO foo VALUES (1);
------------------------------------------------------------------------
@pgr0ss
pgr0ss / config.ru
Created Nov 15, 2011
Simple rack app
View config.ru
require 'stringio'
rack_app = Proc.new do |env|
body = env.map {|k,v| "#{k} => #{v}"}.join("\n")
[ 200, {"Content-Type" => "text/plain"}, StringIO.new(body)]
end
run rack_app
View ccexp.rb
def ccexp?(str)
month, year = str.split("/")
if year.to_i < 10
true
elsif year.to_i == 10
month.to_i <= 6
else
false
end
end
View mask.rb
def mask n;n.slice(0,6)+"*"*(n.size-10)+n.slice(-4,4);end
View request_processor.rb
class RequestProcessor
@queue = :requests
APP = Rack::Builder.new do
use Rails::Rack::Static
use Rack::CommonLogger
run ActionController::Dispatcher.new
end
RACK_BASE_REQUEST = {
View proxy_with_queue.js
var sys = require('sys'),
http = require('http'),
redis = require("./redisclient");
var queuedRes = {}
var counter = 1;
http.createServer(function (req, res) {
pushOnQueue(req, res);
}).listen(8000);
View proxy_with_balance_file.js
var fs = require('fs'),
sys = require('sys'),
http = require('http');
http.createServer(function (req, res) {
checkBalanceFile(req, res);
}).listen(8000);
function checkBalanceFile(req, res) {
fs.stat("balance", function(err) {