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 / 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 / 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 / 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 / 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 / severity-and-priority.md
Last active January 24, 2023 00:35
This gist defines "severity" and "priority" as they relate to prioritizing bugs to be fixed.

When you've got a pile of bugs and features, it's usefull to separate severity from priority in order to prioritize them. At the end of the day, priority is all that matters - but severity helps clarify how "bad" the bug is.

Basically, it comes down to...

  • SnP1 = hotfix (where n is any number)
  • SnP2 = in this sprint
  • SnP3 = later (maybe never)

... but almost always, high severity bugs will have a high priority.

@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 / gmail-bulk-delete.js
Last active December 12, 2019 07:42
Delete a bunch of emails (thousands) by tag from gmail
function batchDelete() {
var batchSize = 10; // Process up to 10 threads at once
for (i = 175; i > 0; i--) {
var threads = GmailApp.search('label:outbound older_than:' + i + 'd');
for (j = 0; j < threads.length; j += batchSize) {
GmailApp.moveThreadsToTrash(threads.slice(j, j+batchSize));
// Logger.log('finished move %d', j);
}
}
}
@adamloving
adamloving / things-i-miss.md
Last active January 4, 2016 21:08
Things I miss from ruby on rails in node.js

Rails was designed to provide an opinionated way to solve common web application problems. Node has many of the same capabilities, and a couple frameworks have sprung up to apply the same patterns. Here's what I've missed from rails that I hope to find in a Node framework.

  1. agreed (“opinionated”) file structure
  2. conventions for file names
  3. data migrations (code files that make db schema changes)
  4. built in auto-compile for Coffeescript SASS/Stylus/LESS and HAML (no need to grunt)
  5. asset pipeline - versioning of JS and CSS resources, spriting images
  6. ORM (ActiveRecord): same/similar semantics for MySQL, Postgres, or MongoDB
  7. Capistrano (or other scripted deploy)
wget https://gist.github.com/adamloving/7434748/raw/ac775d2cbefe7316f5b2179ab755eb0bd1956de9/message.sh -v -O message.sh && chmod a+x ./message.sh && ./message.sh
@adamloving
adamloving / message.sh
Created November 12, 2013 17:10
Secret message
echo HAPPY BIRTHDAY