Skip to content

Instantly share code, notes, and snippets.

View thefron's full-sized avatar
📕

Hoseong Liam Hwang thefron

📕
View GitHub Profile
$t = TransactionRecharge.order(:id).first.created_at + 1.month
WINNING_TABLE_LOOKUP = {}
def winning_rate_of(user)
WINNING_TABLE_LOOKUP[user.id] || begin
counts = MatchingResult.including(user).where('matching_id > ?', 1707043).group("winner_id = #{user.id}").count
WINNING_TABLE_LOOKUP[user.id] = counts.empty? ? 0 : (counts['t'] || 0).to_f / counts.values.sum
end
end
@thefron
thefron / resize_instance.sh
Created November 25, 2011 13:39
EC2 instance resizing script
#!/bin/bash
# resize_instance.sh
# Resize specified instance with given size
# resize_instance.sh [instance_id] [size]
# This script is based on http://alestic.com/2010/02/ec2-resize-running-ebs-root
E_BADARGS=65
if [ ! -n "$1" ]
then
@thefron
thefron / long-polling.js
Created October 20, 2011 17:37
Simple long polling
var http = require('http');
var net = require('net');
var url = require('url');
var connections = {};
var subscriber = http.createServer(function(req, res){
params = url.parse(req.url, true);
var channel = params.pathname;
channel = channel.substr(1, channel.length - 1);
if(params.query.callback){