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 / 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
/*
* 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
#
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>

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 / mysql-docker.sh
Created September 11, 2017 10:32 — forked from spalladino/mysql-docker.sh
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
@leckylao
leckylao / getSubArraysOfSum.js
Created August 1, 2020 04:21 — forked from mo7amd/getSubArraysOfSum.js
Get all sub-arrays of array arr[] with sum k
/*
References:
==============
1: HTTPS://WWW.QUORA.COM/WHAT-IS-THE-RECURSIVE-SOLUTION-FOR-FINDING-ALL-SUBSETS-OF-A-GIVEN-ARRAY
2: HTTPS://WWW.IDESERVE.CO.IN/LEARN/GENERATE-ALL-SUBSETS-OF-A-SET-RECURSION
hellow world from emacs
*/