Skip to content

Instantly share code, notes, and snippets.

View vishaltelangre's full-sized avatar

Vishal Telangre vishaltelangre

View GitHub Profile
@vishaltelangre
vishaltelangre / rails_3_insecure_defaults.md
Last active December 15, 2015 15:49
Rails 3 Insecure Defaults (Notes)

Rails 3 Insecure Defaults

By default Rails does not provide CSRF protection for any HTTP GET request
match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
  • Best Practice:
  • Either specify HTTP verbs or use via: :all when adding routes with #match
@vishaltelangre
vishaltelangre / ie_inspector.js
Last active December 15, 2015 20:41
Fuckin' IE Detection, the "hawt" way!
// @author: Vishal Telangre <the@vishaltelangre.com>
// Published under MIT license.
//
// Requires: jQuery
//
// Usage:
//
// ieInspector.isIe
// -- returns
// - true for IE browsers
@vishaltelangre
vishaltelangre / hosts_zero
Created April 8, 2013 11:57
Poor man's adblocker!
# This hosts file is brought to you by Dan Pollock and can be found at
# http://someonewhocares.org/hosts/zero/
# You are free to copy and distribute this file, as long the original
# URL is included. See below for acknowledgements.
# Please forward any additions, corrections or comments by email to
# hosts@someonewhocares.org
# Last updated: Apr 7th, 2013 at 13:35

Sublime Text 2 – Useful Shortcuts

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
Ctrl+⇧+↩ insert line before
Ctrl+⇧+↑ move line (or selection) up
@vishaltelangre
vishaltelangre / places_controller.rb
Last active December 16, 2015 08:19
[GMaps4Rails]: Create map after an ajax request (solution for the problem of map not getting created in the dom)
# places_controller.rb
class PlacesController < ApplicationController
def index
@place[:map_data] = Places.find(params[:id]).to_gmaps4rails
respond_to do |format|
format.html
end
end
end
/**
* Read the JavaScript cookies tutorial at:
* http://www.netspade.com/articles/javascript/cookies.xml
*/
/**
* Sets a Cookie with the given name and value.
*
* name Name of the cookie
* value Value of the cookie
// USAGE
function Person(el) {
this.name = '';
$(el).change(jQuery.proxy(function(event) {
this.name = event.target.value;
}, this));
}
@vishaltelangre
vishaltelangre / mysql_dump_restore.sh
Last active December 16, 2015 08:29
MySQL dump and restore commands
# take dump of specific db
mysqldump -u vishal -p foo_db_dev > foo_db_dev_dump.sql
# take dump of all available databases
mysqldump -u vishal -p -r -A > foo_db_dev_dump.sql
# import dump of specific db
mysql --verbose -u vishal -p --default-character-set=utf8 foo_db_dev < foo_db_dev_dump.sql
@vishaltelangre
vishaltelangre / try_alternative.rb
Created April 17, 2013 17:14
Alternative to try try
def try_chain
yield
rescue NoMethodError
nil
end
def title
try_chain { output.data.title }
end
@vishaltelangre
vishaltelangre / flash_support.js
Created April 17, 2013 17:16
Check Adobe flash plugin support for browser
// check flash support for visitor browser
function isFlashSupported() {
var hasFlash = false;
try {
var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if(fo) hasFlash = true;
}catch(e){
if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) {
hasFlash = true;
}