Skip to content

Instantly share code, notes, and snippets.

@hiendinhngoc
hiendinhngoc / 0_reuse_code.js
Last active August 29, 2015 14:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hiendinhngoc
hiendinhngoc / rails_resources.md
Last active August 29, 2015 14:12 — forked from jookyboi/rails_resources.md
Rails-related Gems and guides to accelerate your web project.

Gems

  • Bundler - Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.
  • rabl - General ruby templating with json, bson, xml, plist and msgpack support
  • Thin - Very fast and lightweight Ruby web server
  • Unicorn - Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels.
  • SimpleCov - SimpleCov is a code coverage analysis tool for Ruby 1.9.
  • Zeus - Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
  • [factory_girl](h
@hiendinhngoc
hiendinhngoc / gist:6a930ca6a74a21427064
Created May 26, 2015 10:00
how to sort a hash base on order of an array
  • It is very easy to sort a hash base on the order of an existed array, we can do this by this code:
hash.sort_by{|k, v| arr.index(k)}
  • And if you want to sort an array of array based on the order of another array:
arr2.sort_by { |e| arr1.index(e[0]) }
#the other way
arr2.sort_by { |element| arr1.index(element.first) }
#the more other way
@hiendinhngoc
hiendinhngoc / gist:a17bdd11c209b45e6913
Created June 3, 2015 18:11
titlelize with the first little word
def titleize(string)
lowercase_word = %w{a an the and but or for nor of}
"#{string}".split.each_with_index.map{|x, index| lowercase_word.include?(x) && index > 0 ? x : x.capitalize}.join(" ")
end
@hiendinhngoc
hiendinhngoc / gist:5f88aa1b5da4f12a8ab4
Created July 12, 2015 16:47
git fetch upstream repository not found(error)

This command may solve this problem: git remote set-url upstream git@github.com:{upstream owner}/{upstream project}.git

@hiendinhngoc
hiendinhngoc / markdown
Created August 4, 2015 10:36
deeper git
- How do you amend a commit message that you just messed up?
git commit --amend -m "New commit message"
git rebase --continue -m "New commit message"
If you've already pushed your commit up to your remote branch, then you'll need to force push the commit with
git push <remote> <branch> --force
# Or
git push <remote> <branch> -f
- How do you view the history of your most recent commits?
https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History
@hiendinhngoc
hiendinhngoc / error_devsie.md
Last active August 29, 2015 14:26
devise error

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
=> The problem may be that you have not defined default_host for test environment. Define default_host inside:
config/environments/test.rb like this:

config.action_mailer.default_url_options = {:host => "localhost:3000"}

This is learning link about ruby on rails

http://mlsdev.com/blog/42