Skip to content

Instantly share code, notes, and snippets.

@pgr0ss
pgr0ss / keybase.md
Created March 14, 2014 02:42
Keybase proof

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:

@pgr0ss
pgr0ss / support.rb
Last active December 15, 2015 07:48
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}\"'"
@pgr0ss
pgr0ss / mysql_deadlock.sql
Created October 19, 2012 05:41
MySQL Deadlock
CREATE TABLE foo (id INT) ENGINE INNODB;
-- session 1 session 2
------------------------------------------------------------------------
BEGIN;
------------------------------------------------------------------------
BEGIN;
------------------------------------------------------------------------
INSERT INTO foo VALUES (1);
------------------------------------------------------------------------
@pgr0ss
pgr0ss / config.ru
Created November 15, 2011 00:44
Simple rack app
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
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
def mask n;n.slice(0,6)+"*"*(n.size-10)+n.slice(-4,4);end
class RequestProcessor
@queue = :requests
APP = Rack::Builder.new do
use Rails::Rack::Static
use Rack::CommonLogger
run ActionController::Dispatcher.new
end
RACK_BASE_REQUEST = {
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);
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) {