Skip to content

Instantly share code, notes, and snippets.

View adamloving's full-sized avatar
💭
10x Ninja Rockstar

Adam Loving adamloving

💭
10x Ninja Rockstar
View GitHub Profile
@adamloving
adamloving / jquery-deferred-pattern.coffee
Last active December 25, 2015 05:19
Example for a friend on how to use jQuery Deferreds
doSomething: ->
d = jQuery.Deferred()
doTheWork: ->
data = hard()
d.resolve(data)
# return a promise which has a subset of the methods on a deferred
# a promise won't allow you to cancel the deferred for example
d.promise()
@adamloving
adamloving / make-deck.coffee
Created September 20, 2013 04:27
Make a powerpoint deck with two slides using officegen. Text on top of background image.
fs = require('fs')
path = require('path')
officegen = require('officegen')
pptx = officegen ('pptx')
slide = pptx.makeNewSlide()
slide.addImage( path.resolve(__dirname, 'mk.jpg' ), { y: 0, x: 0,cy: '100%', cx: '100%' } )
@adamloving
adamloving / example.coffee
Created September 18, 2013 16:40
showing inheritance with coffeescript
#<html>
#<head>
#<script src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
#<script src="example.js"></script>
#</head>
#<body>
#<h1>Example</h1>
#</body>
#</html>
@adamloving
adamloving / example.js
Last active February 15, 2018 22:45
Beautiful Javascript. This is an example of what I think good Javascript formatting looks like (my style guidelines). Fork this and show me how you like it, or comment if I forgot anything.
// camel case variable names (no underscores)
// instance variables are nouns
var myArray = [1, 2, 3]; // space after commas
// title case for class names (class names should be nouns)
// space before bracket
function Widget() {
// two spaces for indentation
var parameterOne = 1;
var parameterTwo = 2;
@adamloving
adamloving / Gruntfile.coffee
Created July 19, 2013 23:52
The best thing I added to my Gruntfile this week.
SUCCESS_PHRASES = ['all good', 'works for me', 'keep it coming', 'yeah baby', 'i like it',
'you\'re good', 'that\'s it', 'nailed it', 'mmm hmmm', 'sweet', 'keep it up', 'yep']
# ...
exec:
notify_ok:
cmd: ->
phrase = SUCCESS_PHRASES[Math.round(Math.random()*(SUCCESS_PHRASES.length-1))]
"say -v Vicki \"#{phrase}\""
@adamloving
adamloving / pkgcloud-sample.coffee
Created July 10, 2013 22:51
Throw-away sample code for uploading files to Rackspace CDN
# docs here:
# https://github.com/nodejitsu/pkgcloud/blob/master/docs/providers/rackspace/storage.md
_ = require('underscore')
walk = require('walk')
pkgcloud = require('pkgcloud')
getClient = ->
pkgcloud.storage.createClient
provider: 'rackspace'
username: process.env.RACKSPACE_USERNAME
@adamloving
adamloving / pkgcloud-test.coffee
Last active December 19, 2015 13:08
I was trying to get a list of buckets (and eventually upload one file), but I couldn't get this to return more than one bucket until I specified the right region.
# docs here:
# https://github.com/nodejitsu/pkgcloud/blob/master/docs/providers/rackspace/storage.md
pkgcloud = require('pkgcloud')
client = pkgcloud.storage.createClient
provider: 'rackspace'
username: process.env.RACKSPACE_USERNAME
apiKey: process.env.RACKSPACE_API_KEY
authUrl: 'https://auth.api.rackspacecloud.com'
region: 'ORD'
@adamloving
adamloving / git-collaborative-workflow.md
Last active January 27, 2024 02:36
Simple Git workflow for collaborating on a project. I wrote this to help a co-worker learn Git (and help me remember after a year of working on my own).

Creating the change

$ git checkout -b my-feature

... modify code ....

$ git add <filename> 
$ git commit -m “my feature is this”
@adamloving
adamloving / useragent.rb
Created April 1, 2013 21:15
Search strings for common user agents to be filtered out of web page view statistics.
# h = {}; Event.all.each { |e| h[e.useragent] = (h[e.useragent] || 0) + 1; }
# h.keys.each { |k| puts "#{h[k]},#{k}"
class UserAgent
# gplus => "Mozilla/5.0 (Windows NT 6.1; rv:6.0) Gecko/20110814 Firefox/6.0"
BOTS = [
{ :name => 'AppEngine', :match => 'AppEngine', :url => 'http://code.google.com/appengine'},
{ :name => 'Embedly', :match => 'Embedly', :url => 'http://support.embed.ly/'},
{ :name => 'news.me', :match => 'news.me', :url => ''},
{ :name => 'Voyager', :match => 'Voyager/1.0', :url => ''},
{ :name => 'bitlybot', :match => 'bitlybot', :url => ''},
0:31 gandhi recognition award had uh... risen
0:35 badminton mind business time
0:39 five-second philbin let's get one first exercise will be recertified he has been
0:43 attached
0:44 one flight and my feet on the ground and i don't understand what we've
0:48 accomplished by this time he was a statement at this point when it was a
0:52 bob dole's last time i was not based on the ground
0:56 finance please and i think years and slowly just before the selling it
1:01 billings if there was right
1:04 ominous phrase things she described him