This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'gosu' # gem install gosu | |
$width, $height = 200, 200 | |
$number_of_v_lines,$number_of_h_lines = 10, 10 | |
$chars = ('a'..'z').to_a | |
class Entity | |
def initialize(x,y,vel, win) | |
@pos, @vel = {x:x, y:y}, vel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
var arr = [ | |
{"name":"my2child1","title":"My 2 Child 1","parent":"my2"}, | |
{"name":"my2child2","title":"My 2 Child 2","parent":"my2"}, | |
{"name":"parent","title":"A single parent"}, | |
{"name":"child-parent","title":"A child parent","parent":"child1"}, | |
{"name":"my","title":"My"}, | |
{"name":"my2","title":"My2"}, | |
{"name":"child1","title":"Child 1","parent":"my"}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/user/bin/env ruby | |
require 'bundler/inline' | |
gemfile(true) do | |
source 'https://rubygems.org' | |
gem 'sinatra', '~> 1.4' | |
gem 'bcrypt', '~> 3.1' | |
end | |
require 'sinatra/base' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BinaryTree | |
class Node | |
attr_reader :word, :count, :left, :right | |
include Enumerable | |
def initialize(word) | |
@word, @count = word, 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < Devise::SessionsController | |
def create | |
resource = warden.authenticate!(:scope => resource_name, :recall => :failure) | |
return sign_in_and_redirect(resource_name, resource) | |
end | |
def sign_in_and_redirect(resource_or_scope, resource=nil) | |
scope = Devise::Mapping.find_scope!(resource_or_scope) | |
resource ||= resource_or_scope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://www.blackdogfoundry.com/blog/moving-repository-from-bitbucket-to-github/ | |
// See also: http://www.paulund.co.uk/change-url-of-git-repository | |
$ cd $HOME/Code/repo-directory | |
$ git remote rename origin bitbucket | |
$ git remote add origin https://github.com/mandiwise/awesome-new-repo.git | |
$ git push origin master | |
$ git remote rm bitbucket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Don’t Repeat Yourself (DRY) in Ruby on Rails | |
#DRY (Don’t Repeat Yourself) is a principle of Software Development to reducing repetition of information or codes. We can #apply DRY quite broadly to database schema, test plan, system, even documentation. And in this post, we will take example of DRY #in Ruby on Rails development. | |
#In particular case, if you find some methods whose definitions are more or less similar, only different by the method name, it #may use meta programming to simplify the things to make your model more clean and DRY. Consider this simple example where we #have an article with three states. | |
#Before | |
class Article < ActiveRecord::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Interest.destroy_all | |
case ActiveRecord::Base.connection.adapter_name | |
when 'SQLite' | |
update_seq_sql = "update sqlite_sequence set seq = 0 where name = 'interests';" | |
ActiveRecord::Base.connection.execute(update_seq_sql) | |
when 'PostgreSQL' | |
ActiveRecord::Base.connection.reset_pk_sequence!('interests') | |
when 'Mysql2' | |
update_seq_sql = "ALTER TABLE interests AUTO_INCREMENT = 1;" | |
ActiveRecord::Base.connection.execute(update_seq_sql) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Extends Easyui tree and makes use of a surrounding panel to save the newly ordered tree. | |
* Minimum tree options are url, saveUrl (this one doesn't exist in easyui tree) and dnd:true | |
* The surrouding panel must have save and cancel tool ('.icon-save', '.icon-cancel') | |
* @flo | |
*/ | |
$.extend(jQuery.fn.tree.methods, { | |
getDataTree: function (jq) { | |
var definitions = [], methods = this; | |
this.getRoots(jq).forEach(function (root) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Scopes for date attribute | |
# https://gist.github.com/2235839 | |
# | |
module Common::DateScope | |
extend ActiveSupport::Concern | |
included do | |
unless respond_to?(:year) |