Skip to content

Instantly share code, notes, and snippets.

View leckylao's full-sized avatar
🎯
Focusing

Lecky Lao leckylao

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

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
leckylao / Permission problems with SSH
Last active August 29, 2015 14:06
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/id_rsa.pub
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
@leckylao
leckylao / gist:365348
Created April 14, 2010 01:36
Rails CMS alternatives
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:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
@leckylao
leckylao / gist:459447
Created July 1, 2010 01:54
Cucumter select datetime
# ripped from http://github.com/robholland/cucumber-rails/commit/10323c578906fe7a3ed2fdab090b7e326796b386
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)
@leckylao
leckylao / gist:459443
Created July 1, 2010 01:52
DateTime parser
DATE_TIME_SUFFIXES = {
: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) ?
/*
* 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>
console.group("inception movie");
@leckylao
leckylao / nginx
Created June 19, 2011 10:16 — forked from thewebfellas/nginx
init script for 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 <ryan.norbauer@gmail.com>
# Modified: Geoffrey Grosenbach http://topfunky.com
#
@leckylao
leckylao / .bashrc
Last active October 11, 2015 01:38
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
PATH=/usr/bin:/usr/local/bin:$PATH
# torquebox
export TORQUEBOX_HOME=~/torquebox-2.1.2
export JBOSS_HOME=$TORQUEBOX_HOME/jboss
export JRUBY_HOME=$TORQUEBOX_HOME/jruby
[core]
autocrlf = false
editor = gvim
[color]
ui = auto
[alias]
st = status
ci = commit
br = branch
co = checkout