Skip to content

Instantly share code, notes, and snippets.


Lecky Lao leckylao

View GitHub Profile
leckylao / .zshrc
Last active Feb 26, 2019
zsh theme that works with multi-user rvm installation rvm-prompt
View .zshrc
# Path to your oh-my-zsh installation.
export ZSH=/Users/leckylao/.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"
# two lines
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 / 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
leckylao / gist:6153567
Created Aug 5, 2013
Ruby Warrior Epic Mode: Level Score: 74 Time Bonus: 5 Clear Bonus: 16 Level Grade: A Total Score: 510 + 95 = 605 Your average grade for this tower is: A Level 1: S Level 2: A Level 3: S Level 4: S Level 5: A Level 6: A Level 7: S Level 8: S Level 9: A
View gist:6153567
class Player
def play_turn(warrior)
@direction ||= :forward
@opposite_direction = opposite_direction(@direction)
@warrior = warrior
@rest ||= false
@action = false
@health ||=
@turn ||= 1
@hit_at_start ||= false
leckylao / gist:6153513
Created Aug 5, 2013
Ruby Warrior Epic Mode 3 years ago: Level Score: 74 Time Bonus: 13 Clear Bonus: 17 Level Grade: S Total Score: 526 + 104 = 630 Your average grade for this tower is: S Level 1: S Level 2: A Level 3: S Level 4: S Level 5: A Level 6: S Level 7: S Level 8: S Level 9: S
View gist:6153513
class Player
def play_turn(warrior)
@action = false
@direction ||= :forward
# shoot_backward!
if warrior.look(:backward)[2].enemy? and !@action
@action = true
View _flash_messages.html.erb
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
<% end %>
leckylao /
Created Feb 1, 2013
validate local cache gem checksums with the one from RubyGems (SHA512):
#!/usr/bin/env sh
set -e
gem=$(basename $2)
home=$(gem env GEM_HOME)
# cd latest/$dir
#!/usr/bin/env sh
set -e
cat unverified | xargs -n 2 -P 20 ./
View .gemrc
:verbose: true
:benchmark: false
http_proxy: http://localhost:3128
:backtrace: true
:bulk_threshold: 1000
:update_sources: true
- http://gems.nms.local:9998
View .gitconfig
autocrlf = false
editor = gvim
ui = auto
st = status
ci = commit
br = branch
co = checkout