Skip to content

Instantly share code, notes, and snippets.

View dylanjha's full-sized avatar

Dylan Jhaveri dylanjha

  • Mux
  • San Francisco
View GitHub Profile
@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 / 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 / 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 / history.sh
Last active April 28, 2017 20:48
See what commands you run in your terminal most often. Run this to see which commands you should create new aliases for. Stolen from here: https://superuser.com/questions/250227/how-do-i-see-what-my-most-used-linux-command-are
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
@dylanjha
dylanjha / express-test.js
Created June 1, 2017 03:03
Testing out express process exit behavior
'use strict'
const express = require('express')
const app = express()
const http = require('http')
const server = http.createServer(app).listen(9000, () => {
console.log('debug', 'express started process:', process.pid)
app.get('/test-1', (req, res, next) => {
@dylanjha
dylanjha / example-1.js
Last active November 2, 2017 23:11
example file for issue
const obj = {}
function doSomething () {
return new Promise((resolve, reject) => {
obj.create({
name: 'Dylan',
username: 'dylan',
photo: 'avatarurl.com',
email: 'dylan@myemail.com'
},

Example 1

  1. User goes to /posts
  2. User goes to /authors/1
  3. User goes to /posts

Example 2

  1. User goes to /authors/1
  2. User goes to /authors/2
@dylanjha
dylanjha / crypto-pbkdf2-example.js
Created November 15, 2017 00:29 — forked from skeggse/crypto-pbkdf2-example.js
Example of using crypto.pbkdf2 to hash and verify passwords asynchronously, while storing the hash and salt in a single combined buffer along with the original hash settings
var crypto = require('crypto');
// larger numbers mean better security, less
var config = {
// size of the generated hash
hashBytes: 32,
// larger salt means hashed passwords are more resistant to rainbow table, but
// you get diminishing returns pretty fast
saltBytes: 16,
// more iterations means an attacker has to take longer to brute force an
const execa = require('execa')
const Listr = require('listr')
const PROD_APP_NAME = '<replace with: heroku name of prod app>'
const STAGING_APP_NAME = '<replace with: heroku name of staging app>'
const tasks = new Listr([
{
title: 'setup git remote - staging',
task: () =>
// an element with class 'font_resize' with css properties:
// * max-height
// * max-width
// * font-size
// the element has children span elements, the font size inside these spans will re resized.
;(function($){
$.fn.fontResize = function(options){
var spans = $('span:visible', this);
var heightMax = parseInt($(this).css('max-height'), 10),