Skip to content

Instantly share code, notes, and snippets.

View iwinux's full-sized avatar
👽

Limbo Peng iwinux

👽
View GitHub Profile
@brentonashworth
brentonashworth / clj.rb
Created December 3, 2009 04:59
Ruby Script to run Clojure
#!/usr/bin/env ruby -wKU
JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home"
JAVA="#{JAVA_HOME}/bin/java"
GIT_ROOT=ENV['GIT_ROOT']
CLJ="/opt/clojure"
LIB="#{GIT_ROOT}/library"
classpath=".:src:test:classes" +
":#{GIT_ROOT}/formpluslogic/fpl-clojure-util/fpl-clojure-util.jar" +
":#{CLJ}/swank-clojure/src/"
/* This is when a refactoring really pays off.
*
* In order to make your code more modular, avoid hard-coding assumptions (or refactor them away).
* The most fundamental, anti-modular assumption in Object-Oriented software is the concrete type of objects.
* Any time you write "new MyClass" in your code (or in Ruby MyClass.new) you've hardcoded
* an assumption about the concrete class of the object you're allocating. These makes it impossible, for example,
* for someone to later add logging around method invocations of that object, or timeouts, or whatever.
*
* In a very dynamic language like Ruby, open classes and method aliasing mitigate this problem, but
* they don't solve it. If you manipulate a class to add logging, all instances of that class will have
# WPF Clock in IronRuby!
# <t-edmor@microsoft.com>
require 'WindowsBase'
require 'PresentationFramework'
require 'PresentationCore'
require 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
class Clock
@maraigue
maraigue / devnull.rb
Created April 17, 2010 15:46
Ruby implementation of null file (like /dev/null on Un*x, NUL on Windows) The newest version is available by "gem install devnull". See also: http://github.com/maraigue/devnull
# NOTE:
# This version is out-of-date.
# Please access http://github.com/maraigue/devnull for the versions under development.
# Ruby implementation of null file (like /dev/null on Un*x, NUL on Windows)
# (C) 2010- H.Hiro(Maraigue) main@hhiro.net
#
# DevNull works like an IO object. For example:
# dn = DevNull.new
# dn.puts "foo" # => nil (do nothing)
@brentkirby
brentkirby / service
Created June 22, 2011 08:50
Unicorn + Runit + RVM
#!/bin/bash -e
#
# Since unicorn creates a new pid on restart/reload, it needs a little extra love to
# manage with runit. Instead of managing unicorn directly, we simply trap signal calls
# to the service and redirect them to unicorn directly.
#
# To make this work properly with RVM, you should create a wrapper for the app's gemset unicorn.
#
function is_unicorn_alive {
@zhasm
zhasm / rm.sh
Created March 22, 2012 08:27
safer rm command
logger ()
{
time=`TZ="Asia/Shanghai" date +"%Y-%m-%d %T"`;
echo "[$time] $*"
}
rm ()
{
local limit=50;
if [ -d $HOME/.local/share/Trash/files ]; then
def quicksel(l,k):
if len(l) <k:
raise ValueError
else:
pivot=l.pop()
lg=filter(lambda x:x>pivot,l)
ll=filter(lambda x:x<=pivot,l)
if len(lg)>=k:
return quicksel(lg,k)
elif len(lg)+1==k:
let bytes = input.as_bytes();
let mut raw = Vec::<u8>::with_capacity(input.len());
for (offset, codepoint) in input.char_indices() {
let c = codepoint as u32;
if (c > 0x40 && c < 0x5b) || (c > 0x60 && c < 0x7b) ||
(c > 0x29 && c < 0x3a) || c == 0x2b || c == 0x2f {
raw.push(bytes[offset]);
} else if codepoint.is_whitespace() || c == 0x3d {
@benbjohnson
benbjohnson / README.md
Last active February 11, 2019 12:10
LuaJIT + Go Integration Test

Create an empty directory, download the code and run it:

$ mkdir /tmp/lj
$ cd /tmp/lj
$ wget https://gist.github.com/benbjohnson/5622779/raw/e53d227ebdbea8d513b62ad076feb3f6ac1c1594/luajit.go
$ go run luajit.go

And you should see:

@humiaozuzu
humiaozuzu / convention.md
Last active May 29, 2019 05:13
Ansible best practice

Ansible best practice

通用规则

  • YAML 使用 2 空格+.yml后缀
  • Jinja 变量前后需要使用空格 {{ var }}
  • YAML 中引用变量时需要用双引号
  • 环境变量全大写,其他变量全小写
  • 所有变量前需要加上 role name 作为前缀,比如 nginx_xxx
  • role 命名使用短横线