Skip to content

Instantly share code, notes, and snippets.

View dylanjha's full-sized avatar

Dylan Jhaveri dylanjha

  • Mux
  • San Francisco
View GitHub Profile
//route
.when('/users/:tab', {
templateUrl: 'views/users/index.html',
controller: 'UsersController'
})
// UsersController
.controller('HomeController', function ($scope, $http, $routeParams) {
$scope.tab = $routeParams.tab
})
@dylanjha
dylanjha / jquery-ui-tabs-1.9.2-patch.js
Created January 9, 2013 19:15
Patch for bug with jquery-ui-tabs api when <head> has a <base href> tag. http://bugs.jqueryui.com/ticket/4941 http://bugs.jqueryui.com/ticket/8637
//this is to patch a bug with the jquery.ui.tabs API
// http://bugs.jqueryui.com/ticket/4941
// http://bugs.jqueryui.com/ticket/8637
// it has to do with the <base href> tag in <head> and jquery.ui.tabs
// being smart about figuring out weather to AJAX a tab or not
;(function() {
var tabsInitialised = false;
var _tabs = $.fn.tabs;
var updateBaseHrefs = function() {
@dylanjha
dylanjha / cheap-conditional.js
Last active December 16, 2015 09:48
cheap way to do a conditional in javascript. If the first part returns a falsy value, the second part doesn't execute
(function(){
o = {}
o.a = 1
o.a == 1 && console.log("o is one:", o.a)
o.a == 2 && console.log("false, this won't run")
o.b && console.log("undefined is falsy, this wont run")
//it's a little nicer than wrapping if{ } statements:
if(o.a == 1) { console.log("o is one:", o.a) }
@dylanjha
dylanjha / super.rb
Last active December 17, 2015 13:09
verifying how Ruby inheritance works
# 2.0.0dev :175 > @three = Three.new
# => #<Three:0x007fad66054540>
# 2.0.0dev :176 > @three.my_method
# im in class three
# im in the module
# im in class two
# im in class one
# @three.my_method_2
# <Three:0x108ca55e0>
@dylanjha
dylanjha / session-token.rb
Created June 11, 2013 18:54
How easy it is to decode your Rails default session encoding.
1.9.3p392 :001 > session = "BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJTVmMGI3OTEzOTMzYzdlMzUwMjAzZTliMDk1NzNlYjkzBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMWQ3RktCWkFJN0ZnOEJ0T0FDRmF4VnhQcXZKdFVBTnYxaHZiRFY0b3FUY2c9BjsARkkiDHVzZXJfaWQGOwBGaQY%3D--d43bf61a0997f65b5c9c1492102bf4f40fabd5fd"
=> "BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJTVmMGI3OTEzOTMzYzdlMzUwMjAzZTliMDk1NzNlYjkzBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMWQ3RktCWkFJN0ZnOEJ0T0FDRmF4VnhQcXZKdFVBTnYxaHZiRFY0b3FUY2c9BjsARkkiDHVzZXJfaWQGOwBGaQY%3D--d43bf61a0997f65b5c9c1492102bf4f40fabd5fd"
1.9.3p392 :002 > Marshal.load(Base64.decode64(session.split("--").first)) =>
{"session_id"=>"5f0b7913933c7e350203e9b09573eb93",
"_csrf_token"=>"d7FKBZAI7Fg8BtOACFaxVxPqvJtUANv1hvbDV4oqTcg=",
"user_id"=>1}
Array.prototype.remove = function(o){
var i = this.indexOf(o)
, v = this[i];
this.splice(i, 1);
return v;
}
@dylanjha
dylanjha / css3-mixins.css.scss
Last active December 19, 2015 09:49
A bunch of handy mixins for SASS. Who ever thought vendor prefixes were a good idea, anyway?
// Border Radius
@mixin round($radius: 4px) {
-moz-border-radius: $radius;
-webkit-border-radius: $radius;
border-radius: $radius;
}
// Box Shadow
@mixin shadow($shadow1: 0 0 4px #0A0A0A, $shadow2:false, $shadow3:false, $shadow4:false, $shadow5:false) {
$params: $shadow1;
@if $shadow2
[color]
ui = true
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
@dylanjha
dylanjha / apply.js
Created August 1, 2013 12:50
The Apply Invocation Pattern
myFn = function(msg){
return msg + this.status;
}
o = { status: "killing it" }
myFn.apply(o, ["Your status is: "])
//>> "Your status is: killing it"
@dylanjha
dylanjha / sope.js
Created August 1, 2013 13:15
Javascript Scope. Most languages with C syntax have block scope. All variables defined in a block ( curly braces ) are not visible from outside of the block. Unfortunately, JS does not have block scope, even though its block syntax suggests that it does. JS has function scope. That means that the parameters and variables defined in a function ar…
var foo = function(){
var a = 3
,b = 5;
var bar = function(){
var b = 7
,c = 11;
//Right here: a == 3, b == 7 and c == 11