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 / parallelize.py
Last active June 19, 2018 22:10
parallelize python method
import multiprocessing, concurrent.futures
from functools import partial
WORKER_THREAD_COUNT = multiprocessing.cpu_count()
def parallelize(partials):
results = []
with concurrent.futures.ProcessPoolExecutor(max_workers=WORKER_THREAD_COUNT) as executor:
jobs = [ executor.submit(p) for p in partials ]
@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 / react-numeral-input.jsx
Created June 24, 2016 23:53
React based HTML input for dollars that disallows decimals and inserts commas.
class NumericInput extends React.Component {
constructor(props = {}) {
super(props)
this.state = {
value: numeral(props.value).format('0,0')
}
}
onChange(e) {
var number = numeral().unformat(e.target.value)
@adamloving
adamloving / viral_gate.html
Created September 5, 2011 05:00
Viral Gate - how to require liking, sharing, or tweeting to reveal content.
<html>
<body>
<!--
This page demonstrates how to hide some content on the page until the
viewer clicks one of the social sharing buttons.
You can see a live demonstration of this technique on this blog post:
http://adamloving.com/internet-programming/gamify
@adamloving
adamloving / show-express-routes-gulp-task.js
Created June 9, 2014 18:23
Gulp task to show the routes in an express app (similar to rails rake routes).
var app = require('../server/app.js').create()
var gulp = require('gulp');
var task = require('./index');
/*
Output all the routes that the app supports
*/
gulp.task('routes', function() {
@adamloving
adamloving / BraintreeViewController.swift
Created April 12, 2016 17:48
Combined (working) Braintree Swift example for iOS 9
import UIKit
import Braintree
let testToken = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiJkODIwNjRmN2ZhZjExNWJiYTI5NjdmNGEwNmM2OWJhZjQxODVjYjJiZjg2NWNkYzRjNzRiZmIzMzdjNmU5MDMwfGNyZWF0ZWRfYXQ9MjAxNi0wNC0xMlQxNjowNzoyOS44MTc4NjgzNjYrMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3ZHY4OWJxOXZtcHIiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvMzQ4cGs5Y2dmM2JneXcyYi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJjaGFsbGVuZ2VzIjpbXSwiZW52aXJvbm1lbnQiOiJzYW5kYm94IiwiY2xpZW50QXBpVXJsIjoiaHR0cHM6Ly9hcGkuc2FuZGJveC5icmFpbnRyZWVnYXRld2F5LmNvbTo0NDMvbWVyY2hhbnRzLzM0OHBrOWNnZjNiZ3l3MmIvY2xpZW50X2FwaSIsImFzc2V0c1VybCI6Imh0dHBzOi8vYXNzZXRzLmJyYWludHJlZWdhdGV3YXkuY29tIiwiYXV0aFVybCI6Imh0dHBzOi8vYXV0aC52ZW5tby5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tIiwiYW5hbHl0aWNzIjp7InVybCI6Imh0dHBzOi8vY2xpZW50LWFuYWx5dGljcy5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tLzM0OHBrOWNnZjNiZ3l3MmIifSwidGhyZWVEU2VjdXJlRW5hYmxlZCI6dHJ1ZSwicGF5cGFsRW5hYmxlZCI6dHJ1ZSwicGF5cGFs
@adamloving
adamloving / node-instagram-search.js
Created March 4, 2016 21:42
Node instagram search example (including getting an access token)
const Instagram = require('instagram-node-lib')
Instagram.set('client_id', 'xxx')
Instagram.set('client_secret', 'xxx')
// to get an access_token
let url = Instagram.oauth.authorization_url({
redirect_uri: 'http://mysite.com'
})
@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 => ''},
@adamloving
adamloving / gist:9c1e9dfe70b339dcba7b
Created February 4, 2016 15:50
Codility binary gap solution
// wrong for trailing 0s, ...
// 6, 328, n=16=2**4 and n=1024=2**10
// n=51712=110010100000000_2 and n=20=10100_2
function solution(N) {
var max = 0;
var currentLength = 0;
while (N > 0) {
var remainder = N % 2;
inGap = remainder === 0;
@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)