Skip to content

Instantly share code, notes, and snippets.

View thefron's full-sized avatar
📕

Hoseong Liam Hwang thefron

📕
View GitHub Profile
@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){
@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
$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
revelations_by_dates = {}
Revelation.select([:id, :created_at]).find_in_batches(batch_size: 10000) do |revelations|
revelations.each do |revelation|
revelations_by_dates[revelation.created_at.to_date.to_s] ||= 0
revelations_by_dates[revelation.created_at.to_date.to_s] += 1
end
end; nil
revelations_by_dates.sort.each do |date, revelations_count|
dates_messages = {}
Message.where(message_type: 'MESSAGE').select([:message_type, :created_at, :id]).find_in_batches(batch_size: 10000) do |messages|
messages.each do |message|
dates_messages[message.created_at.to_date.to_s] ||= 0
dates_messages[message.created_at.to_date.to_s] += 1
end
end; nil
dates_messages.each do |date, messages_count|
dates_matchings = {}
Matching.unscoped.select([:id, :created_at]).find_each do |matching|
dates_matchings[matching.created_at.to_date.to_s] ||= 0
dates_matchings[matching.created_at.to_date.to_s] += 1
end; nil
dates_matchings.sort.each do |date, matchings_count|
puts "#{date}\t#{matchings_count}"
end; nil
birthyears_users = {}
User.unscoped.registered.select([:id, :birthday]).find_each do |user|
if user.birthday
birthyears_users[user.birthday.year] ||= []
birthyears_users[user.birthday.year] << user.id
else
birthyears_users[0] ||= []
birthyears_users[0] << user.id
end
@thefron
thefron / .zshrc
Created January 23, 2014 05:42 — forked from Veraticus/.zshrc
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Example aliases
@thefron
thefron / deploy.rb
Created February 9, 2014 20:41
Node.js deploy /w Capistrano 3
# config/deploy.rb
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'my_app'
set :repo_url, '[email protected]:USER/my_app.git'
# Default deploy_to directory is /var/www/my_app
set :deploy_to, '/var/node/my_app'
@thefron
thefron / gist:9343238
Created March 4, 2014 09:38
Install puppet open source version with latest version
1. `$ sudo rpm -ivh https://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm`
2. Edit priority of puppetlabs repository
```
[puppetlabs-products]
name=Puppet Labs Products El 6 - $basearch
baseurl=http://yum.puppetlabs.com/el/6/products/$basearch
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
enabled=1