Skip to content

Instantly share code, notes, and snippets.

View alvinsj's full-sized avatar

Alvin alvinsj

  • Singapore
View GitHub Profile
# To fix:
# LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
# Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
# Reason: image not found – /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
# from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
# from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’
# from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7
# from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require’
# from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require’
# from (irb):1
@alvinsj
alvinsj / daemon.rb
Last active December 15, 2015 15:38
Setup Proxy Server in Ruby
require 'daemons'
Daemons.run('./proxy.rb')
@alvinsj
alvinsj / gist:5245030
Created March 26, 2013 12:32
chmod 644 to files, 755 to directories
$ find /path/to/dir -type f -print0 | xargs -I {} -0 chmod 0644 {}
$ find /path/to/dir -type d -print0 | xargs -I {} -0 chmod 0755 {}
@alvinsj
alvinsj / data.rb
Last active December 14, 2015 21:39
custom liquid filter + drop
class Data
attr_accessor :date_range
def initialize(type)
@type = type
end
def graph_points
SomeClass.graph_points(
@type,
@alvinsj
alvinsj / memoize.rb
Last active December 14, 2015 08:28
redis memoization, sidekiq background job (with unique job)
module Memoize
def remember(klass, method_name)
klass.class_eval do
memory = $redis
original = "original_#{method_name}"
original_method = method(method_name)
define_singleton_method(method_name) do |*args|
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
// Must be server-side images; non-origin images will result in a security exception
var images = ["img.jpg"];
for (var i=0;i<images.length;i++) {
thumbnailify(images[i]);
@alvinsj
alvinsj / _breadcrumb.html.erb
Last active December 12, 2015 03:29
simple breadcrumb in rails
<ul class="breadcrumb" id="breadcrumb" >
<li>
<%= breadcrumbs.join("<span class='divider'>/</span></li><li>").html_safe %>
</li>
</ul>
@alvinsj
alvinsj / .profile
Created February 4, 2013 07:56
"alias" for rails4
rails4(){ /PARENT_PATH_TO_RAILS/rails/railties/bin/rails "$@" ; }
@alvinsj
alvinsj / application.js.coffee
Last active December 12, 2015 02:49
link_to_add_fields "Add Field", f, :fields
$(document).on 'click', 'form .remove_fields', (event) ->
$(this).prev('input[type=hidden]').val('1')
$(this).closest('fieldset').hide()
event.preventDefault()
$(document).on 'click', 'form .add_fields', (event) ->
time = new Date().getTime()
regexp = new RegExp($(this).data('id'), 'g')
$(this).before($(this).data('fields').replace(regexp, time))
event.preventDefault()
.table-view {
width:100%;
height:100%;
overflow:scroll;
}
.table-view-cell{
width:100%;
height:30px;
border: 1px solid #c0c0c0;
cursor: pointer;