Skip to content

Instantly share code, notes, and snippets.

@Martin91
Martin91 / auto_set_tab_chrome_background_color.sh
Last active August 29, 2015 14:04
set iTerm2 tab chrome background color according to the current working directory
function auto_set_tab_chrome_background_color {
# Red component value is calculated from the full path of current directory
RR=`pwd | wc -m`
let RR=(RR%25)*10
# Green component value is calculated from the basename of current directory
GG=`basename \`pwd\` | wc -m`
let GG=(GG%25)*10*2
# Blue component value is calculated from the full total files and directories count under this directory
@Martin91
Martin91 / final_version.rb
Last active August 29, 2015 14:04
simple socket server to loop accept connections
require 'socket'
Socket.tcp_server_loop(4481) do |connection| # 处理连接。
# 必要的处理
connection.close
end
@Martin91
Martin91 / octopress_pdf_tag.rb
Created August 19, 2014 15:40
Support octopress project to generate pdf previews from pdf files to png images, and render <img> tags
# Title: PDF previewer for Octopress
# Author: Martin (http://martin91.github.io/)
# Description: Convert a pdf file into a series of images, and then output a html
# <ul> block with each <li></li> correspond to each image orderly.
#
# Syntax {% pdf_tag relative/path/to/pdf/file/under/source/directory %}
#
# Example:
# {% pdf_tag WebRTC introduction %}
#
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
@Martin91
Martin91 / environment_config.rb
Created August 30, 2014 05:46
use custom fonts in rails
# Using fonts in Rails
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/
@Martin91
Martin91 / pin_payments_subscriptions_research.md
Created September 3, 2014 04:19
Pin Payments Subscriptions Integration Research
  1. Sync plans List all active plans
[8] pry(main)> RSpreedly::SubscriptionPlan.active
=> [#<RSpreedly::SubscriptionPlan:0x000001051e4be0
  @description="<description>",
  @duration_quantity=12,
  @duration_units="months",
 @id=25113,
@Martin91
Martin91 / port_server.rb
Last active August 29, 2015 14:06
ruby network address and por detecter
#!/usr/bin/ruby
require 'socket'
class PortServer
attr_reader(:port,:server)
def initialize(port)
@port = port
end
@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
@Martin91
Martin91 / replace_hash_key.rb
Created September 11, 2014 09:55
Replace hash key
hash[:new_key] = hash.delete :old_key
@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)