Skip to content

Instantly share code, notes, and snippets.


Lecky Lao leckylao

View GitHub Profile
leckylao / web_sockets_in_rails.rb
Last active Aug 29, 2015
WebSocket in Ruby on Rails
View web_sockets_in_rails.rb
# encoding: utf-8
center <<-EOS
WebSocket in Ruby on Rails
Lecky Lao(@leckylao)
RORO 11-02-2013
View gist:cb9c504c8aeccd3b9e86

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.

A traditional approach for this on a Rails project is to use something like the acts_as_list gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position SQL query.

This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri

leckylao / Permission problems with SSH
Last active Aug 29, 2015
Permission problems with SSH
View Permission problems with SSH
Ssh is very picky about permissions on the ~/.ssh directory and files. Sometimes you may do something to mess up these permissions. Run the following to fix most permissions problems. You may have to do this on both the remote host and local host.
SSH will not work correctly and will send warnings to the log facilities if any variation of g+w or o+wexists on the $HOME directory
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
leckylao / gist:365348
Created Apr 14, 2010
Rails CMS alternatives
View gist:365348
Rails CMS alternatives
Note: project activity was checked on 11/26/09 for most of these projects, and the "last update" field has not been kept up to date since then.
Active projects:
Last update: 11/24/09
leckylao / gist:459447
Created Jul 1, 2010
Cucumter select datetime
View gist:459447
# ripped from
module Cucumber
module Rails
module CapybaraSelectDatesAndTimes
def select_date(field, options = {})
date = Date.parse(options[:with])
within(:xpath, Capybara::XPath.fieldset(field).append(%Q{//p[label[contains(., "#{field}")]]})) do
find(:xpath, '//select[contains(@id, "_1i")]').select(date.year)
View gist:459443
:year => '1i',
:month => '2i',
:day => '3i',
:hour => '4i',
:minute => '5i'
def select_date(date_to_select, options={})
date = date_to_select.is_a?(Date) || date_to_select.is_a?(Time) ?
View inception-javascript.js
* Fabrizio Calderan, twitter @fcalderan, 2010.11.02
* I had an idea: could Inception movie be explained by a few javascript closures
* and variable resolution scope (just for fun)?
* Activate javascript console =)
<script>"inception movie");
leckylao / nginx
Created Jun 19, 2011 — forked from thewebfellas/nginx
init script for nginx
View nginx
#! /bin/sh
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
# Author: Ryan Norbauer <>
# Modified: Geoffrey Grosenbach
View .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# torquebox
export TORQUEBOX_HOME=~/torquebox-2.1.2
View .gitconfig
autocrlf = false
editor = gvim
ui = auto
st = status
ci = commit
br = branch
co = checkout