Skip to content

Instantly share code, notes, and snippets.

View dylanjha's full-sized avatar

Dylan Jhaveri dylanjha

  • Mux
  • San Francisco
View GitHub Profile

Inconsistent uri encoding with parenthesis. Notice in the first 3 examples the parenthesis are still there, in the fourth example the parenthesis are replaced with %28 and %29:

This is the string being encoded in each example: www.google.com?q=some string with (parens)

===

Javascript (node 6.9.0):

encodeURI("www.google.com?q=some string with (parens)")
@dylanjha
dylanjha / hosts
Created October 21, 2016 19:18
add this to /etc/hosts file
192.30.253.112 github.com
192.30.253.119 gist.github.com
151.101.44.133 assets-cdn.github.com
@dylanjha
dylanjha / test.html.erb
Created March 22, 2015 03:21
Rake task to load erb
<%# Put this file in app/views/test.html.erb %>
<h1>Here is some html</h2>
<%= name %>
//route
.when('/users/:tab', {
templateUrl: 'views/users/index.html',
controller: 'UsersController'
})
// UsersController
.controller('HomeController', function ($scope, $http, $routeParams) {
$scope.tab = $routeParams.tab
})
@dylanjha
dylanjha / 0. sprockets_depend_on_config.rb
Last active May 11, 2020 15:11
Adds Sprockets Directive `depend_on_config`. I'm using this to load .yml locale translations on the server into the client in json
=begin
Useage:
#assets/locales/en.js.erb
```js
//= depend_on_config 'locales/es.yml'
```
=end
@dylanjha
dylanjha / 1. application.html.erb
Last active January 31, 2016 17:55
Set a `currentUser` in Ember world that all controllers ( and all views ) can access. I'm using Ember 1.5.0 and Ember Data 1.0.0-beta.6
<!DOCTYPE html>
<html>
<head>
<title>App</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= javascript_include_tag "templates/all" %>
<%= csrf_meta_tags %>
</head>
<body>
@dylanjha
dylanjha / js-testing.js
Last active January 1, 2016 15:49
Am I doing this wrong? My goal here is to set up a constructor that I can test. The first bit is how I would normally create this new constructor MyObject... the second bit shows how I have to change it in order to test some of the internal functions. See my first comment below.
//this constructor, MyObject is supposed to only have 1 publically exposed method: .getResults()
;(function ( $, window, document, undefined ) {
window.MyObject = function(params){
var error = params.error;
function _shouldFireRequest = function(){
//some logic
return boolean
@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
@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"
[color]
ui = true
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold