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 / 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>
@adamloving
adamloving / when-spread-example.coffee
Created Sep 24, 2015
When.js spread function turns array of parameters into arguments.
View when-spread-example.coffee
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 Sep 24, 2015
When using when.js, should you put the catch first or last in the promise chain?
View promise-chain-catch.coffee
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 Sep 4, 2015
Ruby example code for finding the intersection of two CSV files full of contacts (exported from Google contacts).
View compare-contacts.rb
#!/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 Jun 25, 2015
running Javascript from Swift using JavaScriptCore (try this in a playground)
View javascript.swift
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 Apr 13, 2015
Redis scan javascript promise (when) example
View redis-scan-promise-iterate.js
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) {
@adamloving
adamloving / swift-command-line.swift
Created Mar 27, 2015
example swift command line script
View swift-command-line.swift
#!/usr/bin/env xcrun swift -i
println("Process.arguments gave args:")
for s in Process.arguments {
println(s)
}
@adamloving
adamloving / HelloPoi.java
Created Mar 25, 2015
Read PowerPoint ppt pptx using Apache Poi in java!
View HelloPoi.java
import java.io.*;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.POIXMLProperties.*;
import org.apache.poi.xslf.usermodel.*;
public class HelloPoi {
public static void main(String[] args) {
@adamloving
adamloving / SortByFrequency.swift
Created Mar 10, 2015
Swift: Sort array of strings by the frequency (how many times) they appear in an array.
View SortByFrequency.swift
// Sort in order by frequency (descending)
var terms = ["a", "b", "a", "c", "a", "b"]
var termFrequencies = [String: Int]()
for t in terms {
if termFrequencies[t] == nil {
termFrequencies[t] = 1
} else {
termFrequencies[t] = termFrequencies[t]! + 1
@adamloving
adamloving / selenium_shooter.js
Created Dec 30, 2014
example of taking a screenshot of a web page using selenium-webdriver
View selenium_shooter.js
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var when = require('when');
var webdriver = require('selenium-webdriver');
exports.takeShot = function(url, outputFilePath) {
return when.promise(function(resolve, reject) {
You can’t perform that action at this time.