Skip to content

Instantly share code, notes, and snippets.

View maxbeatty's full-sized avatar

Max Beatty maxbeatty

View GitHub Profile
@maxbeatty
maxbeatty / gist:96350e9adc423c6c752a
Created December 26, 2014 19:05
Recruiter tries to program
Subject: If employment = false....
var money = a lot;
var opportunity = amazing;
var technology = cutting edge;
var people = cool;
var awesomejob = money + opportunity + technology + people;
if (awesomejob = false && employment = available) alert('We have a great opportunity for you here at [redacted]!')
@maxbeatty
maxbeatty / node-encrypt-decrypt.js
Created November 5, 2014 03:22
Encrypt and decrypt a string with Node.js
crypto = require('crypto');
exampleClientId = 'my_client_id'
mySharedKey = 'shared_key'
cipher = crypto.createCipher('aes256', mySharedKey)
cipherText = cipher.update(exampleClientId, 'utf8', 'base64')
cipherText += cipher.final('base64')
decipher = crypto.createDecipher('aes256', mySharedKey)
@maxbeatty
maxbeatty / gist:f70a6cf72c7c2c4cc1a8
Created October 20, 2014 04:34
SSL caveat when installing nginx via homebrew
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local.
Mac OS X already provides this software and installing another version in
@maxbeatty
maxbeatty / jeff-icon.sass
Created September 17, 2014 19:00
Adventures in Spriting
$lowRes: sprite-map("chat/sprites/*.png")
$highRes: sprite-map("chat/sprites-retina/*.png")
.chat-icon
margin-right: 10px
cursor: pointer
+sprite-background(message-icon, $lowRes, $highRes)
&:hover
+sprite-background(message-icon_hover, $lowRes, $highRes)
&.unread
@maxbeatty
maxbeatty / obfuscate.html
Created August 4, 2014 03:12
How I'm obfuscating email addresses in 2014
<p>
<strong>First Last</strong> whatever.
</p>
<a href="javascript:void(0)" class="pick-me">Email Me</a>
<script>
// sets href to "mailto:firstlast@domain.com"
document.querySelector('.pick-me').onclick = function (e) {
this.href = [
@maxbeatty
maxbeatty / postmortem.coffee
Created July 30, 2014 02:20
Be careful how you update and delete with Sequelize
require('dotenv').load()
db = require './server/lib/db'
addressRepo = require './server/repositories/addressRepository'
db.sequelize.sync().complete (err) ->
throw err if err
addressRepo.findAll {}, (err, addresses) ->
throw err if err
console.log addresses.length + ' addresses to begin with'
@maxbeatty
maxbeatty / collection.coffee
Created July 9, 2014 02:31
Promises make dealing with validation + AJAX cases a breeze when testing
saveDraft: -> $.Deferred (deferred) =>
# do validation
validationError = @validate()
if validationError
# use deferred to return immediately with failure
return deferred.reject validationError
$.post @url, @toJSON()
@maxbeatty
maxbeatty / key-obj.litcoffee
Created July 2, 2014 16:50
CoffeeScript checking if key exist in object

You would think it works just like JavaScript:

'pushState' in window.history

But this actually compiles to:

var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
__indexOf.call(window.history, 'pushState') >= 0;

What you want to do is use of instead of in:

@maxbeatty
maxbeatty / index.js
Created June 30, 2014 20:56
Detecting extensions in Express.js (v3) route
var express = require('express'),
app = express();
app.configure(function() {
app.use(app.router);
app.use(function(req, res, next) { res.send(404); });
});
app.get('/:name', function(req, res, next) {
var re = /\.(csv|pdf)$/,
@maxbeatty
maxbeatty / index.js
Created May 30, 2014 16:41
Global config via JSON file in Node (`node index.js`)
global.config = require('./path-to-config.json');
require('./other');