Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Lecky Lao leckylao

🎯
Focusing
Block or report user

Report or block leckylao

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@leckylao
leckylao / mysql-docker.sh
Created Sep 11, 2017 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
View mysql-docker.sh
# 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 / 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/id_rsa.pub
chmod 644 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/known_hosts
@leckylao
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
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
EOS
@leckylao
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 ||= warrior.health
@turn ||= 1
@hit_at_start ||= false
@leckylao
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
warrior.shoot!(:backward)
@action = true
end
@leckylao
leckylao / gist:6118148
Created Jul 30, 2013
Gitlab permission hack and SSH Permissions
View gist:6118148
Current Gitlab having permission issues on the Git/Gitlab user folders, which prevents creating new projects.
Steps to fix change permission back in order to create new project
change gitlab service to run with gitlab user instead of root
Change from:
# sudo -u gitlab -H bash -l -c "rvm use 1.9.3-p327; bundle exec unicorn_rails $DAEMON_OPTS >> $LOG 2>&1 &"
# sudo -u gitlab -H bash -l -c "rvm use 1.9.3-p327; mkdir -p $PID_PATH && nohup bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook RAILS_ENV=production PIDFILE=$RESQUE_PID >> $LOG 2>&1 &"
bundle exec unicorn_rails $DAEMON_OPTS >> $LOG 2>&1 &
mkdir -p $PID_PATH && nohup bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook RAILS_ENV=production PIDFILE=$RESQUE_PID >> $LOG 2>&1 &
To:
sudo -u gitlab -H bash -l -c "rvm use 1.9.3-p327; bundle exec unicorn_rails $DAEMON_OPTS >> $LOG 2>&1 &"
View puma
#! /bin/bash
### BEGIN INIT INFO
# Provides: puma
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
View puma
#!/bin/sh
#
# puma - this script starts and stops the puma daemon
#
# chkconfig: - 85 15
# description: Description \
# goes here...
# processname: puma
# config: /etc/puma.conf
# pidfile: /home/stanislaw/apps/micro-apps/puma/puma.pid
You can’t perform that action at this time.