Skip to content

Instantly share code, notes, and snippets.

View ryancheung's full-sized avatar
🌝

Ryan Cheung ryancheung

🌝
  • Earth
View GitHub Profile
@ryancheung
ryancheung / pubsub.coffee
Last active December 21, 2015 04:18
Simple pubsub implementation in coffee
window.ActiveAdminSortableEvent = do ->
eventToListeners = {}
return {
add: (event, callback) ->
if not eventToListeners.hasOwnProperty(event)
eventToListeners[event] = []
eventToListeners[event].push(callback)
trigger: (event, args) ->

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Running local YARD server

regenerates docs for each request

require 'bundler/capistrano'
set :application, "net"
set :repository, "git@githost.com:net.git"
set :scm, :git
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
@ryancheung
ryancheung / randutils.hpp
Created July 26, 2016 04:48 — forked from imneme/randutils.hpp
Addresses common issues with C++11 random number generation; makes good seeding easier, and makes using RNGs easy while retaining all the power.
/*
* Random-Number Utilities (randutil)
* Addresses common issues with C++11 random number generation.
* Makes good seeding easier, and makes using RNGs easy while retaining
* all the power.
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Melissa E. O'Neill
*
@ryancheung
ryancheung / vim.txt
Last active August 15, 2016 06:55
VIM replace by regex in all file
:arg **/**.{h,cpp}
:argdo %s/\(new NextAction(.\{-})\)/NextActionPtr(\1)/ge | update
:argdo %s/\(new NextAction([^()]*)\)/NextActionPtr(\1)/ge | update
@ryancheung
ryancheung / inplace_edit_file.rb
Created August 15, 2016 10:43
Inplace edit file with regexp
files = Dir["./**/**.{h,cpp}"]
def inplace_edit(file, bak, &block)
old_stdout = $stdout
argf = ARGF.clone
argf.argv.replace [file]
argf.inplace_mode = bak
argf.each_line do |line|
yield line
#include <iostream>
void bubble_sort(int arr[5]) {
for (int i = 0; i < 5; ++i) {
for (int j = 1; j < (5 - i); ++j) {
if (arr[j-1] > arr[j]) {
int temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
@ryancheung
ryancheung / yardoc_cheatsheet.md
Created January 11, 2017 05:34 — forked from chetan/yardoc_cheatsheet.md
YARD cheatsheet

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Modules

Namespace for classes and modules that handle serving documentation over HTTP

@ryancheung
ryancheung / hmac-sha1.rb
Created March 27, 2017 09:44 — forked from kovacshuni/hmac-sha1.rb
Ruby HMAC-SHA1 digest creation
require 'base64'
require 'cgi'
require 'openssl'
base = 'POST&https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521'
key = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE'
puts CGI.escape(Base64.encode64("#{OpenSSL::HMAC.digest('sha1', key, base)}\n"))
@ryancheung
ryancheung / deploy.rb
Created April 8, 2013 07:01
Capistrano config file example with Resque and Resque Scheduler
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user # Literal ":user"
set :application, "blog_test"
set :repository, "git@github.com:ryancheung/blog.git"
set :scm, :git