Skip to content

Instantly share code, notes, and snippets.

define ['require', 'jquery', 'utils/index'], (require, $, utils) ->
decorator = ($target) ->
moduleName = $target.attr('data-module')
require [moduleName], ((module) ->
if $.isFunction module.decorate
data = $target.data()
delete data.module
module.decorate $target, data
@joshhunt
joshhunt / nock.coffee
Created October 24, 2014 03:53
sinon vs spy
describe 'get', ->
beforeEach ->
@sc = new Sitecore baseUrl, 'app'
afterEach ->
nock.cleanAll()
it 'should call the correct URL for an item', ->
nock baseUrl
// This wont work
myApp.controller('EditProfileCtrl', function(UserResource) {
// This is a reference to _this_ current function (most of the time - its a good rule of thumb).
this.isLoading = false
UserResource.get({id: userID})
.$promise.then(function(){
// So in here, we're in a new function, so its a compltely different 'this'
this.isLoading = false
@joshhunt
joshhunt / prompt.fish
Last active September 9, 2020 02:31
Fish Shell Git Prompt
# Git prompt, heavily modified from the g2 fish prompt. https://github.com/orefalo/g2/tree/master/fish
#
# Inspired from bobthefish is a Powerline-style, Git-aware fish theme optimized for awesome.
#
# You will probably need a Powerline-patched font for this to work:
#
# https://powerline.readthedocs.org/en/latest/fontpatching.html
# https://github.com/Lokaltog/powerline-fonts
set -g current_bg NONE
@joshhunt
joshhunt / kim.txt
Last active August 29, 2015 14:11
Break the internet
-hMMMMMMM+
`dMMMMMMMM/
:MMMMMMNNNNd
`./shhdMMMMMMmMNNd
-ymMMMMMMMMMMMMNNNs`
.yNMMMMMMMMMMMMMMMd.
`/+oooshdNMMMMMMMMMMh`
/:-.``-/oshMMMMMMMMMMy
::..` .:+ohNMMMMNMMMMd
@joshhunt
joshhunt / gist:7433a7496aff505ccbbb
Created May 3, 2015 04:58
Create loaders from a shim config
makeLoaderFromShim = (toShim, fileName) ->
_makeGlobalLoader = (toShim) -> "exports?#{toShim}"
filenameRegex = new RegExp "^#{fileName}$"
if _.isString toShim
loader = _makeGlobalLoader toShim
{test: filenameRegex, loader: loader}
AWS = require 'aws-sdk'
s3 = new AWS.S3()
bucketName = 'lambda-test'
region = 'us-east-1'
key = 'testData.json'
module.exports = (event, context) ->
console.log JSON.stringify(event, null, 2)
console.log 'From SNS:', event.Records[0].Sns.Message
@joshhunt
joshhunt / correct.js
Last active August 29, 2015 14:23 — forked from benjamingr/correct.js
function createUser(username, callback) {
DatabaseClient.connect()
.then(function(connection) {
return connection.collection('users')
})
.then(function(users) {
return users.query({username: username})
})
.then(function(exising){
if(existing) {
randomChoice = (items) ->
item = items[Math.floor(Math.random()*items.length)]
shuffle = (array) ->
currentIndex = array.length
temporaryValue = randomIndex = null
# While there remain elements to shuffle...
while 0 isnt currentIndex
# Pick a remaining element...
@joshhunt
joshhunt / .tmux.conf
Last active August 29, 2015 14:27
tmux conf
###
### You'll need to install the Powerline fonts and set them up for your terminal
### https://github.com/powerline/fonts
###
#
# -- Init -------------------------------------------------
#