Skip to content

Instantly share code, notes, and snippets.

View feixionglee's full-sized avatar

feixionglee feixionglee

  • Shanghai, China
View GitHub Profile
@feixionglee
feixionglee / postfix.rb
Last active August 29, 2015 14:03
calculate expression
# '( 2 + ( ( 4 + 6 ) * (9 * 2) - ( 5 - 1)))'
class Postfix
include Math
def initialize expression
@expression = expression.gsub(' ', '')
end
def process
@feixionglee
feixionglee / postfix_test.rb
Created July 5, 2014 23:53
calculate expression
require '/Users/lifeixiong/Desktop/postfix/postfix'
require "minitest/autorun"
class PostfixTest < Minitest::Test
def setup
@postfix = Postfix.new '2*(1+3)'
end
def test_is_digit
assert @postfix.send :is_digit, 0
@feixionglee
feixionglee / unicorn
Last active August 29, 2015 14:05
unicorn init script with rbenv
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts unicorn
# Description: starts uniconr using start-stop-daemon
@feixionglee
feixionglee / deployment version track
Last active December 29, 2015 18:59
deployment version track
use the following code in a Rails initializer
if Rails.env.production?
commit_hash = `git rev-parse HEAD 2>/dev/null`.to_s.strip
APP_VERSION = Time.now.utc.strftime("%Y%m%d-%H%M-") + commit_hash[-8..-1]
else
APP_VERSION = Time.now.utc.strftime("%Y%m%d-%H%M-development")
end
@feixionglee
feixionglee / 0_reuse_code.js
Created April 27, 2017 02:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@feixionglee
feixionglee / check_slave_status.rb
Created July 20, 2017 06:52 — forked from blasterpal/check_slave_status.rb
Check MySQL Slave status from Shell using Ruby
#!/usr/bin/env ruby
@slave_status = Hash[%x(mysql -uroot -e 'SHOW SLAVE STATUS \\\G').split(/\s*\n\s*/).map { |e| spl = e.split(/\:\s*/); spl.size == 2 ? [spl.first, spl.last] : nil }.compact]
def slave_healthy?
@slave_status['Slave_IO_Running'] == 'Yes' &&
@slave_status['Slave_SQL_Running'] == 'Yes' &&
@slave_status['Seconds_Behind_Master'] != 'NULL' &&
@slave_status['Seconds_Behind_Master'].to_i < 1800
end
@feixionglee
feixionglee / quick_sort.rb
Last active June 15, 2020 15:22
Quick sort algorithm implement with Ruby
# frozen_string_literal: true
class QuickSort
def initialize(array)
@array = array
end
def sort
puts @array
quick_sort(0, @array.size - 1)