Skip to content

Instantly share code, notes, and snippets.

<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /rails_app_directory/public
# Redirect all requests that don't match a file on disk under DocumentRoot get proxied to Puma
RewriteEngine On
<Proxy balancer://unicornservers>
BalancerMember http://127.0.0.1:5100
@Martin91
Martin91 / ansi_colors.rb
Last active August 29, 2015 14:13
ANSI codes for ruby strings
# ansi_colors.rb
# Implement add ansi color escape code to normal string
#
# Created by Martin Hong on 1/17/2015
# Copyright (c) 2015 Martin Hong. All rights reserved.
#
String.class_eval do
# ==== Start colors with ANSI escape code ====
#
@Martin91
Martin91 / 英文文章词频统计.md
Last active July 26, 2024 08:23
题目:英文文章词频统计

英文文章词频统计需求说明

需要实现以下所有功能:

  1. 从指定文件(参数传递)中读取需要分析的英文文章
  2. 计算文章所有单词加标点符号的数量
  3. 单独计算所有单词数量
  4. 单独计算所有标点符号的数量
  5. 统计每个单词在文中出现的频数
@Martin91
Martin91 / main.m
Created January 6, 2015 08:31
Words counter in Objective-C
//
// main.m
// words-statistics
//
// Created by Martin Hong on 1/5/15.
// Calculate the total count of words in a speficified paragraph.
//
// Features:
// 1. 计算文章所有单词加标点符号的数量
// 2. 单独计算文章所有单词的数量
@Martin91
Martin91 / set_iterm2_tab_color.sh
Created November 6, 2014 10:28
Set iTerm2 tab color when cd and open new tab
# ~/.bash_profile
function cd {
# actually change the directory with all args passed to the function
builtin cd "$@"
auto_set_tab_chrome_background_color;
}
function auto_set_tab_chrome_background_color {
@Martin91
Martin91 / nginx_start_up_script.sh
Created October 25, 2014 04:40
Nginx Startup Script
#! /bin/sh
# /etc/init.d/nginx
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
@Martin91
Martin91 / simple_notificaiton_system.rb
Created October 24, 2014 15:35
simple example to read email addresses from excel and send notifications to each email address
require 'rubygems'
require 'net/smtp'
require 'roo'
def load_receivers
receivers = []
excel_file = Roo::Excel.new(ENV['EXCEL'])
2.upto(excel_file.last_row).each do |row|
# Assume that the name is in the second column, and email is in the third column.
@Martin91
Martin91 / block_bad_spider.rb
Created October 15, 2014 08:30
Block Bad Spider
# Copied from https://gist.github.com/rainchen, original author: https://github.com/rainchen
#
# set in application.rb
# config.middleware.insert_after 'Rack::MethodOverride', 'BlockBadSpider'
class BlockBadSpider
def initialize(app)
@app = app
end
def call(env)
@Martin91
Martin91 / replace_hash_key.rb
Created September 11, 2014 09:55
Replace hash key
hash[:new_key] = hash.delete :old_key
@Martin91
Martin91 / port_client.rb
Created September 5, 2014 14:57
Ruby client to request the public address and port
require 'socket'
include Socket::Constants
client = TCPSocket.open 'example.com', 1234
begin
retry_counter = 0
client.write( "GET / HTTP/1.0\r\n\r\n" )
results = client.read