Skip to content

Instantly share code, notes, and snippets.

View v2e4lisp's full-sized avatar

Yan Wenjun v2e4lisp

View GitHub Profile

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
module ActiveAdmin
module Reports
module DSL
def enable_reports
action_item only: :index do
link_to("Download", {action: :report, params: params}, {method: :post, data: { confirm: "Are you sure you want to generate this report?"}})
end
collection_action :report, method: :post do
# == Booting process
#
# The application is also responsible for setting up and executing the booting
# process. From the moment you require "config/application.rb" in your app,
# the booting process goes like this:
#
# 1) require "config/boot.rb" to setup load paths
# 2) require railties and engines
# 3) Define Rails.application as "class MyApp::Application < Rails::Application"
# 4) Run config.before_configuration callbacks
@v2e4lisp
v2e4lisp / json-repl.rb
Created August 19, 2014 10:29
json repl for ruby
require 'readline'
module Repl
module Command
class PWD
def self.parse argv=nil
dir = Repl::Container.dirs.last
'/' + (dir ? dir.join('/') : '')
end
@v2e4lisp
v2e4lisp / pbcopy.el
Created August 6, 2014 05:28
copy to clipboard from emacs in terminal
;; copy to clipboard from emacs in terminal
;;
;; if you use emacs in tmux you should enable pbcopy in tmux first
;; http://superuser.com/questions/231130/unable-to-use-pbcopy-while-in-tmux-session
(defun pbcopy-region (start end)
(interactive "r")
(pbcopy (buffer-substring start end)))
(defun pbcopy (string)
#
# A C Parser using the Parslet library.
#
# ANSI C Grammar:
#
# * http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
# * http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
#
require 'parslet'
@v2e4lisp
v2e4lisp / ruby.ext.md
Last active August 29, 2015 14:03
ruby ext memo

RUBY.ext

Test a ruby object is truthy | Tield block

  • RTEST(VALUE rb_obj)
  • rb_yield(VALUE rb_obj) yield a value to given block. For multiple values, rb_assoc_new them first

example

@v2e4lisp
v2e4lisp / gist:bfc22cc52a04f0947f1d
Created July 2, 2014 06:26
extract deb file on os x
ar -vx libssl-dev_1.0.1h-3_amd64.deb  

tar -xvzf libssl-dev_1.0.1h-3_amd64.deb data.tar.xz 

tar xvfJ data.tar.xz 
@v2e4lisp
v2e4lisp / hooka.rb
Last active August 29, 2015 14:03
ruby before/after hook
module Hooka
class Returning < Struct.new(:value, :returning); end
def self.included(base)
base.extend ClassMethods
end
def returning(value=nil)
throw :hook_stop, Returning.new(value, true)