Skip to content

Instantly share code, notes, and snippets.

View v2e4lisp's full-sized avatar

Yan Wenjun v2e4lisp

View GitHub Profile
var request = require('request');
var ZabbixApi = function(user, password, api_url) {
this.user = user;
this.password = password;
this.api_url = api_url;
this.id = 0;
};
ZabbixApi.prototype.post = function(data, fn) {
@v2e4lisp
v2e4lisp / gist:6350775
Last active December 21, 2015 18:59
parsing json-like data. Designed for cli use. It's far from effient. The funny thing is you can customize the special mark of the json-like data.
module Fakeit
extend self
attr_accessor :array_mark, :hash_mark
@array_mark = '[ ]'
@hash_mark = '{:,}'
# Not effient way to parse json-like structure
# The problem is `split` is called too many times.
# The better way to do it, is something like the original js json parser .
# It's done by using only one pass.
Rails3 - CheatSheet - CommandLine
rails new ApplicationName – Create a new application
rails _3.0.9_ new ApplicationName – Create a new application with a specific version of rails
rails generate/g model ModelName – Creates a model with the specified model_name
rails generate/g controller ControllerName – Creates a controller with the specified controller_name
rails generate/g migration MigrationName – Creates a migration with the specified migration_name
rails generate/g scaffold ModelName ControllerName – A shortcut for creating your controller, model and view files etc.
rails destroy controller ControllerName – Destroys the created controller and its related file.
rails destroy model - Destroys the created model and its related file.
(defvar <- "\\(")
(defvar -> "\\)")
(defalias '@ 'regexp-quote)
(defun re/start-of-line (&optional next)
(concat "^" next))
(defun re/end-of-line (&optional next)
(concat "$" next))
Hello World
@v2e4lisp
v2e4lisp / underscore.py
Created July 12, 2013 11:09
underscore.py
import random
class _:
def __init__(self, data):
if isinstance (data, _): return data
self.data = data
def value (self):
return self.datan
def each (self, func):
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@v2e4lisp
v2e4lisp / pick
Created June 20, 2013 04:53
ruby hash pick
class Hash
def pick(*args)
result = {}
args.each do |k|
result[k] = self[k]
end
result
end
end
a = {a: 1 , b: 2, c: 3}
@v2e4lisp
v2e4lisp / links
Created June 14, 2013 07:13
links
;;; real-time-markdown.el --- Mou in emacs .
;; Author: Wenjun Yan <mylastnameisyan@gmail.com>
;; Version: 0.1
;; URL: https://gist.github.com/v2e4lisp/5613374
;; Package-Requires: ((impatient-mode "0.1"))
;;
;; Copyright (C) 2013 Wenjun Yan
;;
;; This program is free software; you can redistribute it and/or modify