This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# '( 2 + ( ( 4 + 6 ) * (9 * 2) - ( 5 - 1)))' | |
class Postfix | |
include Math | |
def initialize expression | |
@expression = expression.gsub(' ', '') | |
end | |
def process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class QuickSort | |
def initialize(array) | |
@array = array | |
end | |
def sort | |
puts @array | |
quick_sort(0, @array.size - 1) |