Skip to content

Instantly share code, notes, and snippets.

View cmthakur's full-sized avatar
🎯
Focusing

Chandra M. Thakur cmthakur

🎯
Focusing
View GitHub Profile
@cmthakur
cmthakur / Heroku Push
Created April 9, 2012 04:00
Heroku Push
rails new checkonce
cd checkonce
git init
git add .
git commit -m"init"
heroku login
gem install heroku
@cmthakur
cmthakur / git frequently used commands
Created April 25, 2012 06:17
git frequently used commands
#force push
git push -f
#track current branch to the remote
git push -u
git branch --set-upstream cmt origin/story/find_connections
#revert to the given saw
git revert <saw_id>
@cmthakur
cmthakur / Build gem with bundler
Created May 24, 2012 05:21
Build a gem with bundler
New gem with bundler
bundle gem gem_name
edit gem_name.gemspec file
gem build gem_name.gemspec
gem push .gem # .gem file generated from above
@cmthakur
cmthakur / Extract the file type in ruby.
Created May 31, 2012 04:25
Extract the file type in ruby.
You can simply find the file type of a file where file.content_type doesnot works
options[:form] = "./lib/cf/cli/templates/sample-line/form.html"
file_type = IO.popen(["file", "--brief", "--mime-type", options[:form]], in: :close, err: :close).read.chomp
The return type is simply "text/html"
@cmthakur
cmthakur / sql commands
Created July 19, 2012 14:18
sql commands
#restore .sql file to the database
mysql target-db-name < sql-file-name.sql -uuser -p
# [mysql dir]/bin/mysql -h hostname -u root -p
Create a database on the sql server.
mysql> create database [databasename];
List all databases on the sql server.
mysql> show databases;
@cmthakur
cmthakur / API
Created August 6, 2012 04:36
API
def show
@product = Product.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @product }
format.xml { render :xml => @product }
end
end
@cmthakur
cmthakur / http errors
Created August 7, 2012 14:57
Rails http error
just one of the HTTP error response codes that Active Resource will handle with its own exception. The following HTTP response codes will also result in these exceptions:
200..399 - Valid response. No exceptions, other than these redirects:
301, 302, 303, 307 - ActiveResource::Redirection
400 - ActiveResource::BadRequest
401 - ActiveResource::UnauthorizedAccess
@cmthakur
cmthakur / Pretty Look
Last active October 9, 2015 10:08
Pretty Look In Sublime Text
# Copy Paste these to Setting - User
{
"bold_folder_labels": false,
"color_scheme": "Packages/Color Scheme - Default/Solarized (Light).tmTheme",
"folder_exclude_patterns":
[
".svn",
".git",
".hg",
@cmthakur
cmthakur / Prefetching
Created September 4, 2012 04:18
Prefetching at client side.
http://www.cmarshall.net/MySoftware/ajax/index.html
http://www.catswhocode.com/blog/mastering-html5-prefetching
http://docs.jquery.com/AjaxQueue
http://api.jquery.com/queue/
http://stackoverflow.com/questions/4666130/how-would-i-design-a-client-side-queue-system
http://www.cmarshall.net/MySoftware/ajax/Threads/
@cmthakur
cmthakur / jquery.preload.js
Created September 18, 2012 09:37 — forked from mathiasbynens/jquery.preload.js
JavaScript preload() function
/*!
* $.preload() function for jQuery – http://mths.be/preload
* Preload images, CSS and JavaScript files without executing them
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/
* Note that since this script relies on jQuery, the preloading process will not start until jQuery has finished loading.
*/
jQuery.preload = function(array) {
var length = array.length,