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 / swift-command-line.swift
Created March 27, 2015 20:43
example swift command line script
#!/usr/bin/env xcrun swift -i
println("Process.arguments gave args:")
for s in Process.arguments {
println(s)
}
@adamloving
adamloving / HelloPoi.java
Created March 25, 2015 21:21
Read PowerPoint ppt pptx using Apache Poi in 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 March 10, 2015 18:48
Swift: Sort array of strings by the frequency (how many times) they appear in an array.
// 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 December 30, 2014 00:48
example of taking a screenshot of a web page using selenium-webdriver
#!/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) {
@adamloving
adamloving / phantom_shooter.js
Created December 30, 2014 00:44
An example of how to take a screenshot using phantom js.
#!/usr/bin/env node
'use strict';
var when = require('when');
var phantom = require('phantom');
exports.takeShot = function takeShot(url, outputFilePath) {
return when.promise(function(resolve, reject) {
@adamloving
adamloving / terms.txt
Created December 29, 2014 02:32
more experimental nupic output
#COUNT TERM ONE TERM TWO TERM THREE |TERM THREE PREDICTION
-----------------------------------------------------------------------------
# 1 fish showed fish | heart
# 2 ignite showed fire | fish
# 3 ignite showed match | fire
# 4 grain showed wheat | fire
# 5 development showed construction | fish
# 6 development showed code | construction
# 7 labor showed worker | fire
# 8 influence showed speaker | fire
@adamloving
adamloving / output.txt
Created December 29, 2014 02:28
nupic nlp experiment output
#COUNT TERM ONE TERM TWO TERM THREE |TERM THREE PREDICTION
-----------------------------------------------------------------------------
# 1 aunt likes baking | programming
# 2 aunt likes piano | baking
# 3 aunt eats vegetables |
# 4 uncle eats chocolate | vegetables
# 5 uncle likes bikes | programming
# 6 uncle eats coffee | chocolate
# 7 uncle likes running | bikes
# 8 uncle eats cereal | coffee
@adamloving
adamloving / streamline-example._coffee
Created December 13, 2014 03:56
my first streamline experiment
#!/usr/bin/env _coffee
console.log 'hello ...'
setTimeout _, 100
console.log '... world'
doSomething = (isError, cb) ->
process.nextTick ->
if isError
cb(new Error('error'), isError)
else
@adamloving
adamloving / confusing-sort.js
Created December 2, 2014 22:44
more confusing sorting
var items = ['0', '000', 0, 1, '001', 'a', 'z', 'A', 'Z', '!', null, undefined];
console.log('sorted', items.sort());
// defaults to string sort null becomes 'null'
// sorted [ '!', '0', 0, '000', '001', 1, 'A', 'Z', 'a', null, 'z', undefined ]
console.log('string sort', items.sort(function(a, b) {
if (a < b) {
console.log(typeof(a), a, '<', typeof(b), b, '== true');
@adamloving
adamloving / string-compare.js
Last active August 29, 2015 14:10
javascript string compare.
if (1 == '1') console.log('1. 1 == "1"');
if (1 === '1') {} else console.log('2. 1 is not === "1" (types different)');
var a = 'a';
var a1 = a;
var a2 = 'a';
if (a == a1) console.log('3. a == a1');
if (a == a2) console.log('4. a == a2');
if (a === a2) console.log('5. even a ==== a2 (equal value and type)');