Skip to content

Instantly share code, notes, and snippets.

💭
10x Ninja Rockstar

Adam Loving adamloving

💭
10x Ninja Rockstar
Block or report user

Report or block adamloving

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adamloving
adamloving / python_sucks.py
Last active May 22, 2019
Python is a very inelegant language. Here are some things I dislike.
View python_sucks.py
# 1. Clunky lambda syntax
numbers = [1, 2, 3]
# don't do this...
doubled = list(map(lambda n: n * 2, numbers))
# There's no way to define the end of the block except that comma. What about wrapping lines?
# better for this case
doubled = [n * 2 for n in numbers]
@adamloving
adamloving / .flake8.ini
Last active Oct 4, 2018
flake8 python linting configuration file
View .flake8.ini
# on macOS, put this in ~/.config/flake8
[flake8]
max-line-length=88
ignore=
#E302 expected 2 blank lines, found 1
E302,
#E261 at least two spaces before inline comment
E261,
# E401 multiple imports on one line
E401,
@adamloving
adamloving / parallelize.py
Last active Jun 19, 2018
parallelize python method
View parallelize.py
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 / react-numeral-input.jsx
Created Jun 24, 2016
React based HTML input for dollars that disallows decimals and inserts commas.
View react-numeral-input.jsx
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 / BraintreeViewController.swift
Created Apr 12, 2016
Combined (working) Braintree Swift example for iOS 9
View BraintreeViewController.swift
import UIKit
import Braintree
let testToken = "eyJ2ZXJzaW9uIjoyLCJhdXRob3JpemF0aW9uRmluZ2VycHJpbnQiOiJkODIwNjRmN2ZhZjExNWJiYTI5NjdmNGEwNmM2OWJhZjQxODVjYjJiZjg2NWNkYzRjNzRiZmIzMzdjNmU5MDMwfGNyZWF0ZWRfYXQ9MjAxNi0wNC0xMlQxNjowNzoyOS44MTc4NjgzNjYrMDAwMFx1MDAyNm1lcmNoYW50X2lkPTM0OHBrOWNnZjNiZ3l3MmJcdTAwMjZwdWJsaWNfa2V5PTJuMjQ3ZHY4OWJxOXZtcHIiLCJjb25maWdVcmwiOiJodHRwczovL2FwaS5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tOjQ0My9tZXJjaGFudHMvMzQ4cGs5Y2dmM2JneXcyYi9jbGllbnRfYXBpL3YxL2NvbmZpZ3VyYXRpb24iLCJjaGFsbGVuZ2VzIjpbXSwiZW52aXJvbm1lbnQiOiJzYW5kYm94IiwiY2xpZW50QXBpVXJsIjoiaHR0cHM6Ly9hcGkuc2FuZGJveC5icmFpbnRyZWVnYXRld2F5LmNvbTo0NDMvbWVyY2hhbnRzLzM0OHBrOWNnZjNiZ3l3MmIvY2xpZW50X2FwaSIsImFzc2V0c1VybCI6Imh0dHBzOi8vYXNzZXRzLmJyYWludHJlZWdhdGV3YXkuY29tIiwiYXV0aFVybCI6Imh0dHBzOi8vYXV0aC52ZW5tby5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tIiwiYW5hbHl0aWNzIjp7InVybCI6Imh0dHBzOi8vY2xpZW50LWFuYWx5dGljcy5zYW5kYm94LmJyYWludHJlZWdhdGV3YXkuY29tLzM0OHBrOWNnZjNiZ3l3MmIifSwidGhyZWVEU2VjdXJlRW5hYmxlZCI6dHJ1ZSwicGF5cGFsRW5hYmxlZCI6dHJ1ZSwicGF5cGFs
@adamloving
adamloving / hover-video.html
Created Mar 22, 2016
Hover to play video
View hover-video.html
<html>
<head>
<style>
.viewport {
position: relative;
width: 300px;
height: 300px;
}
.viewport:hover img {
@adamloving
adamloving / node-instagram-search.js
Created Mar 4, 2016
Node instagram search example (including getting an access token)
View node-instagram-search.js
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 / base-neg-2.js
Created Feb 8, 2016
Toptal Codility Problem: Convert to-and-from base -2
View base-neg-2.js
'use strict';
function toDecimal(A) {
var sum = 0;
for (var i = 0; i < A.length; i++) {
sum += A[i] * Math.pow(-2, i);
}
return sum;
}
@adamloving
adamloving / gist:9c1e9dfe70b339dcba7b
Created Feb 4, 2016
Codility binary gap solution
View gist:9c1e9dfe70b339dcba7b
// 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 / react-toggle.js
Created Oct 22, 2015
Bootstrap button group toggle react js example
View react-toggle.js
var ProjectForm = React.createClass({
getInitialState: function() {
return { headerText: 'nothing' }
},
handleToggleChange: function(value) {
this.setState({ headerText: value.toUpperCase() })
},
render: function() {
return (
<form>
You can’t perform that action at this time.