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 / lost-my-shit.md
Created April 23, 2014 21:20
How to find your shit

Where is apache?

$ which apachectl

It's not a symlink, so it must be mac version! Where's the confthing?

$ apachectl -V | grep conf

Where's PHP?

@adamloving
adamloving / callback-vs-deferred.md
Last active August 29, 2015 14:01
Writing clean code with a callback pattern vs. deferreds.

Guidelines

  1. Only nest the simplest of functions
  2. Give functions a name
  3. Seems weird to pass callback function as an argument

The callback way

async.parallel([
@adamloving
adamloving / diy-node-hosting.md
Last active August 29, 2015 14:01
Node.js hosting best practices. How to host node in production.

Hosting Node.js

We need to host node ourselves (Rackspace server) to have access to the file system (temp files for image processing) and (legacy) local database.

Have you hosted node in production? If so, what was the web server setup? Currently, we're using nginx + a unix socket file + forever or upstart. My inclination is to stop hosting it ourselves and go for a PaaS (like heroku) - but that's because I wish this stuff was not my problem. What I'm looking for is a clear recipe for best practices.

Issues

Hosting node is hard because unhandled errors force the node.js v8 process to die and need a restart.

@adamloving
adamloving / auto-fbpost.rb
Created May 26, 2014 23:06
Post several links to a Facebookpage
#!/usr/bin/env ruby
# foreman run script/social/auto-fbpost.rb data/crawl-data.json
# To get page access token, go to graph explorer, get user token with manage_pages and publish_actions permission,
# then request /{userId}/accounts
require 'koala'
require 'json'
graph = Koala::Facebook::API.new(ENV['FB_PAGE_ACCESS_TOKEN'])
urls = JSON.parse(File.open(ARGV.first).read)
@adamloving
adamloving / auto-twitter-post.rb
Created May 26, 2014 23:07
Post several links to twitter feed
#!/usr/bin/env ruby
# foreman run script/social/auto-tweet.rb data/crawl-data.json
require 'Twitter'
require 'json'
client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['TWITTER_API_KEY']
config.consumer_secret = ENV['TWITTER_API_SECRET']
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
@adamloving
adamloving / array-reference.php
Created May 30, 2014 20:48
Daily PHP WTF. Adding a key to an array creates a new and different array.
<?php
$a = array();
$b = $a;
// "When using the identity operator (===), object variables are identical
// if and only if they refer to the same instance of the same class."
if ($a === $b) print "same\n";
$a['test'] = 'something';
@adamloving
adamloving / coffee-map-hack.js
Created June 30, 2014 05:53
Compile coffee script with source map at require time.
var CoffeeScript = require('coffee-script')
// CoffeeScript.register()
function requireCoffeeScript(relativePath) {
var path = require('path');
var fs = require('fs');
relativePath = path.resolve(__dirname, relativePath);
console.log('relativePath', relativePath);
@adamloving
adamloving / minecraft-profile.sh
Created August 10, 2014 01:18
fetch (verify) a minecraft profile
curl -d '{"name":"notch","agent":"minecraft"}' -H 'Content-Type: application/json' https://api.mojang.com/profiles
# http://skins.minecraft.net/MinecraftSkins/<USERNAME>.png for skin
@adamloving
adamloving / playground.swift
Created August 19, 2014 20:12
Playing around with JSON and images
import SpriteKit
var str = "Hello, playground"
var dict : [String: String] = ["hi": "there"]
let productData = "{\"data\":[{\"url\": \"http://s2.img-b.com/build.com/imagebase/resized/330x320/moenimages/moen-tl182p-65.jpg\"}]}"
var error: NSError?
@adamloving
adamloving / babelfish.py
Last active August 29, 2015 14:07
Sublime Text 3 plugin to detect window modification (couldn't figure out how to update other window)
# put this in /Users/adam/Library/Application Support/Sublime Text 3/Packages/User/babelfish.py
import sublime, sublime_plugin
class Bablefish(sublime_plugin.EventListener):
def on_modified(self, view):
print(view.file_name(), "modified")
w = view.window()