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 / hover-video.html
Created March 22, 2016 23:01
Hover to play video
<html>
<head>
<style>
.viewport {
position: relative;
width: 300px;
height: 300px;
}
.viewport:hover img {
@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 / base-neg-2.js
Created February 8, 2016 21:41
Toptal Codility Problem: Convert to-and-from base -2
'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 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 / react-toggle.js
Created October 22, 2015 18:47
Bootstrap button group toggle react js example
var ProjectForm = React.createClass({
getInitialState: function() {
return { headerText: 'nothing' }
},
handleToggleChange: function(value) {
this.setState({ headerText: value.toUpperCase() })
},
render: function() {
return (
<form>
@adamloving
adamloving / when-spread-example.coffee
Created September 24, 2015 18:09
When.js spread function turns array of parameters into arguments.
w = require 'when'
w.all [
w.resolve(1)
w.resolve(2)
]
.then console.log
w.all [
w.resolve('a')
@adamloving
adamloving / promise-chain-catch.coffee
Last active September 24, 2015 18:08
When using when.js, should you put the catch first or last in the promise chain?
w = require 'when'
# When using when, should you put the catch first or last in the promise chain?
# You should put it last if you want it to end the chain before your thens run.
doSomethingAndFail = (n) ->
console.log 'fail', n
w.reject(n)
doSomethingAndFail(1)
@adamloving
adamloving / compare-contacts.rb
Created September 4, 2015 03:20
Ruby example code for finding the intersection of two CSV files full of contacts (exported from Google contacts).
#!/usr/bin/ruby
# Usage: compare-contacts.rb [file1] [file2]
require 'csv'
def find_email_column_indexes(row)
[
row.index('E-mail Address'),
row.index('E-mail 2 Address'),
row.index('E-mail 3 Address'),
row.index('E-mail 1 - Value'),
@adamloving
adamloving / javascript.swift
Created June 25, 2015 19:40
running Javascript from Swift using JavaScriptCore (try this in a playground)
import JavaScriptCore
let context = JSContext()
context.evaluateScript("var num = 5 + 5")
context.evaluateScript("var names = ['Grace', 'Ada', 'Margaret']")
context.evaluateScript("var triple = function(value) { return value * 3 }")
context.evaluateScript("names.sort()")
let tripleNum: JSValue = context.evaluateScript("triple(num)")
@adamloving
adamloving / redis-scan-promise-iterate.js
Created April 13, 2015 23:41
Redis scan javascript promise (when) example
var count = 0;
when.iterate(function(args) {
var cursor = parseInt(args[0]);
return redis.whenZScan('mykey', cursor || 0);
}, function predicate(args) {
var cursor = parseInt(args[0]);
return cursor === 0;
}, function handler(args) {
if (args.length > 1) {