Skip to content

Instantly share code, notes, and snippets.

@taiansu
taiansu / destructuring.coffee
Created June 20, 2012 17:35
More about JavaScript & CoffeeScript arguments
motorcycle = ({ brand, year } = { brand: 'Unknown', year: "1999" }) ->
alert "brand: #{brand}, year: #{year}"
motorcycle()
#brand: 'Unknown', year: "1999"
motorcycle year:"2005", brand:"YAMAHA"
#brand: 'YAMAHA', year: 2005
@taiansu
taiansu / running_number.rb
Created November 7, 2012 08:12
Running Number in Ruby
class RunningNumber
attr_accessor :prefix, :current
def initialize(prefix = 'RUN', current = '000000')
@prefix = prefix
@current = current
end
def current
@prefix + @current
@taiansu
taiansu / application.html.erb
Created November 12, 2012 17:29
Bootstrap flash notice
<body>
<div class="container">
<% flash.each do |name, msg| %>
<div class="alert alert-<%= name == :notice ? "success" : "error" %>">
<a class="close" data-dismiss="alert">x</a>
<%= msg %>
</div>
<% end %>
</div>
<!-- Rest of content -->
@taiansu
taiansu / _form.html.erb
Created November 12, 2012 17:30
Bootstrap _form validation
<%= simple_form_for @record, :html => { :class => 'form-horizontal' } do |f| %>
<fieldset>
<legend><%= controller.action_name.capitalize %></legend>
<%= f.input :title %>
<%= f.input :amount %>
<%= f.association :category %>
<%= f.input :date %>
<div class="form-actions">
<%= f.submit nil, :class => 'btn btn-primary' %>
@taiansu
taiansu / application.css.scss
Created December 9, 2012 17:22
CashNotes nav_bar
/*
...
*/
@import "twitter/bootstrap/bootstrap";
body{ padding-top: 60px; }
@import "twitter/bootstrap/responsive";
@taiansu
taiansu / populate.rake
Created December 9, 2012 18:20
in lib/tasks
namespace :db do
desc "Erase and fill database"
task :populate => :environment do
require 'populator'
#require 'faker'
[Category, Record].each(&:delete_all)
Category.populate 10 do |category|
category.title = Populator.words(2)
@taiansu
taiansu / Gemfile
Created December 15, 2012 19:05
CashNotes' chart with Morris.js
gem 'raphael-rails'
gem 'morrisjs-rails'
gem 'gon'
#...
@taiansu
taiansu / records.js.coffee
Created December 18, 2012 12:08
Morris.js record
jQuery ->
Morris.Line
element: 'chart'
data: [
{y: '2012', a: 100}
{y: '2011', a: 75}
{y: '2010', a: 50}
{y: '2009', a: 75}
{y: '2008', a: 50}
{y: '2007', a: 75}
@taiansu
taiansu / ubuntu_ruby21.sh
Last active December 18, 2015 15:59
install ruby 2.1 in ubuntu
#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get --no-install-recommends -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison pkg-config libffi-dev vim
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
cd
@taiansu
taiansu / dynamic_hash.rb
Created July 2, 2013 08:00
Dynamic hash
class DynamicHash < Hash
def []=(key, val)
super
self.class.class_eval do
define_method(key) do
self[key]
end
define_method("#{key}=") do |value|
self[key] = value
end