Skip to content

Instantly share code, notes, and snippets.

View shunchu's full-sized avatar

Shun Chu shunchu

View GitHub Profile
@shunchu
shunchu / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created July 25, 2012 07:58
Convert seconds into HH:MM:SS in Ruby
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@shunchu
shunchu / video-thumbnails-generator.sh
Created November 15, 2012 18:00
Batch generate thumbnails from mp4 files using ffmpg
#!/bin/bash
# setup
FILES=name_of_file_to_match_*.mp4
SEEK_POINT=00:00:30
IMG_FORMAT=png
FRAME_SIZE=150X100
DEST=thumbnails
for f in $FILES
@shunchu
shunchu / macos-10.12-brewfile
Last active March 2, 2018 00:35
macos 10.12 brewfile
tap "caskroom/cask"
tap "caskroom/drivers"
tap "caskroom/fonts"
tap "homebrew/bundle"
tap "homebrew/core"
tap "homebrew/science"
tap "homebrew/services"
brew "ack"
brew "readline"
brew "autoconf"
@shunchu
shunchu / dotfile-zshrc
Last active December 22, 2017 21:24
dotfile zshrc
source ~/.aliases
source ~/.exports
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
# load zgen
ZGEN_PREZTO_LOAD_DEFAULT=0
source "${HOME}/.zgen/zgen.zsh"
# if the init scipt doesn't exist
@shunchu
shunchu / .ruby-version
Last active August 6, 2017 15:01
chruby hack for chefdk
chefdk
@shunchu
shunchu / display-ember-promise-errors.js
Last active August 4, 2017 03:26
display ember promise errors
// source: https://ianpetzer.wordpress.com/2013/07/24/dont-let-ember-js-swallow-errors-in-your-promises/
Ember.RSVP.configure('onerror', function(e) {
console.log(e.message);
console.log(e.stack);
});
@shunchu
shunchu / components.my-component.js
Last active December 15, 2016 18:06
New Twiddle
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
const { inject: { service } } = Ember;
export default Ember.Component.extend({
ajax: service(),
result: null,
queryTask: task(function* (term) {
yield timeout(600);
@shunchu
shunchu / ways_to_create_ruby_singleton_methods.rb
Last active December 20, 2015 01:18
Ways to create Singleton Methods in Ruby
# Reference: http://madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html
class Dog
def self.closest_relative
"wolf"
end
end
class Dog
class << self
@shunchu
shunchu / no-ruby-gem-docs
Created May 10, 2013 18:01
Don't install Ruby gem docs while installing gems
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
@shunchu
shunchu / pg.rake
Created July 8, 2012 10:25 — forked from royratcliffe/pg.rake
Rake task to dump PostgreSQL structure using a compatible pg_dump
namespace :pg do
namespace :structure do
# Does exactly the same as db:structure:dump but with one important
# difference. It tries to use a compatible version of pg_dump. If you see
# the following error message, use pg:structure:dump instead.
#
# pg_dump: server version: 9.1.0; pg_dump version: 9.0.4
# pg_dump: aborting because of server version mismatch
# rake aborted!
# Error dumping database