Skip to content

Instantly share code, notes, and snippets.

@Martin91
Martin91 / route.sh
Last active August 29, 2015 14:21 — forked from kevinzhow/route.sh
# routes rule for ocserv
route = 8.0.0.0/255.0.0.0
route = 58.0.0.0/255.0.0.0
route = 23.0.0.0/255.0.0.0
route = 117.0.0.0/255.0.0.0
route = 199.0.0.0/255.0.0.0
route = 190.0.0.0/255.0.0.0
route = 198.0.0.0/255.0.0.0
route = 173.0.0.0/255.0.0.0
route = 174.0.0.0/255.0.0.0
@Martin91
Martin91 / ocserv
Last active August 29, 2015 14:21 — forked from kevinzhow/ocserv
#!/bin/sh
### BEGIN INIT INFO
# Provides: ocserv
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
# Copyright Rene Mayrhofer, Gibraltar, 1999
# This script is distibuted under the GPL
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@Martin91
Martin91 / cascadingSelect.js.coffee
Last active August 29, 2015 14:21
级联选择,自动发现下级控件
# 在 jQuery 的原型中添加一个新的方法,作为级联选择的插件
#
# options:
# fetchNextNode: function($node){} 用于如何发现下级控件的回调函数,必须返回节点数组
#
$.fn.cascadingSelect = (options = {})->
currentNode = $rootNode = $(this)
otherNodes = options['fetchNextNode']($rootNode)
listenChange = (node)->
@Martin91
Martin91 / active_record-base_decorator.rb
Last active August 29, 2015 14:21
Rails active record human enum values
# #{Rails.root}/config/initializers/active_record/base_decorator.rb
ActiveRecord::Base.class_eval do
def self.human_enum_values(enum_name = nil)
enum_name ||= defined_enums.keys.first
raise "Could not find a enum named #{enum_name} in #{name}" unless enum_values = defined_enums[enum_name]
_human_enum_values = {}
enum_values.each do |key, value|
translated_key = I18n.t "activerecord.enums.#{name.underscore}.#{enum_name}.#{key}"
@Martin91
Martin91 / params_cleaner.rb
Created May 6, 2015 15:49
对参数结构进行重构,以通过 grape 的数组参数验证,并且与 Rails 的参数机制兼容
# 将参数 {associations_attributes: {"1" => {xxx: xxx}, "2" => {xxx: xxx}}} 中的 Hash 型参数转为数组型:
# =>
# {
# associations_attributes: [
# {xxx: xxx},{xxx: xxx}
# ]
# }
#
# 满足 grape 中 type: Array[OtherTypeName]的验证
#
@Martin91
Martin91 / install_pptp.sh
Created May 6, 2015 15:38
install pptp on ubuntu vps
# https://www.digitalocean.com/community/tutorials/how-to-setup-your-own-vpn-with-pptp
# Step 1 - PPTP Installation
sudo apt-get install pptpd
# edit /etc/pptpd.conf and add the following lines:
# localip is IP address of your server and remoteip are IPs that will be assigned to clients that connect to it
localip 10.0.0.1
remoteip 10.0.0.100-200
# Step 2 - Add DNS servers to /etc/ppp/pptpd-options
@Martin91
Martin91 / detectMobileBrowser.js
Last active August 29, 2015 14:16
Detect mobile browser
function isMobileBrowser() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibr
@Martin91
Martin91 / qrcode_size.rb
Created January 27, 2015 09:09
determine the size for qrcode
# size - seems to follow this logic
# codes copied from:
# => https://raw.githubusercontent.com/samvincent/rqrcode-rails3/master/lib/rqrcode-rails3/size_calculator.rb
#
# # | input | modules
# | size | created
#-------|-------|--------
# 1 | 7 | 21
# 2 | 14 | 25 (+4)
# 3 | 24 | 29 -
@Martin91
Martin91 / base64_uploaded_file.rb
Created January 27, 2015 07:35
save base64 file as uploaded
class XXXController < ApplicationController
def create
moment = Moment.new photo: preprocess_uploaded_photo
# ...
end
def preprocess_uploaded_photo
encoded_photo_data = params[:moment][:photo]