Skip to content

Instantly share code, notes, and snippets.


Lecky Lao leckylao

View GitHub Profile
leckylao / getSubArraysOfSum.js
Created August 1, 2020 04:21 — forked from mo7amd/getSubArraysOfSum.js
Get all sub-arrays of array arr[] with sum k
View getSubArraysOfSum.js
hellow world from emacs
leckylao /
Created September 11, 2017 10:32 — forked from spalladino/
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
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

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 / nginx
Created June 19, 2011 10:16 — 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 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 / gist:365348
Created April 14, 2010 01:36
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