Skip to content

Instantly share code, notes, and snippets.

View oscarmorrison's full-sized avatar

Oscar Morrison oscarmorrison

View GitHub Profile
@oscarmorrison
oscarmorrison / countWordsInText.js
Last active January 14, 2017 21:20
count the words in a string, and order by popularity
let text = "There’s an interesting discussion on Quora about the differences between Golang and Scala. As a former academic with tendencies towards functional programming, I used to be very tempted by Scala.1 It offers all the functional goodness without the exoticism of Haskell, and came with reasonably good tools and frameworks. Like Clojure, it’s a functional language you can actually do some work with. The problem with Scala is, the more advanced you get, the more complicated (unreadable?) your code becomes. I remember that back in grad school the dude who was able to doodle the craziest and mathematically most challenging solution to some problem in Haskell was someone everyone looked up to. But it turns out in the “real world” simplicity always trumps virtuosity and sophistication, which is one of the many reasons I love Golang so much. A language with no “magic,” good concurrency support, great documentation and community that compiles into machine code and runs faster than Python? Yes, please. Read th
#blog.oscarmorrison.com
#Cat feeder (open and close server)
#change the pin, and port here.
from flask import Flask, jsonify
import RPi.GPIO as IO
import time
pinOut = 4
app = Flask(__name__)
@oscarmorrison
oscarmorrison / uniqueArray.js
Last active December 4, 2016 18:01
Unique Array
const uniqueArray = function(array) {
return array.filter(function (item, pos) {
return array.indexOf(item) == pos;
})
}
@oscarmorrison
oscarmorrison / external.js
Last active December 3, 2016 17:08
Make all external links open in new tab
$('a[href^=http]').each(function(){
if(this.href.indexOf(location.hostname) < 0) {
$(this).attr({target: '_blank'});
}
});
@oscarmorrison
oscarmorrison / mysportsclubactivitydetails.js
Created November 11, 2016 14:44
Boston Sports Club Scrape
/*jslint node: true */
/*jshint esversion: 6 */
'use strict';
var Nightmare = require('nightmare');
var moment = require('moment');
var debug = false;
var nightmare = new Nightmare({
show: debug,
@oscarmorrison
oscarmorrison / gist:6ebd9344e16448121ef4a5cdea1427b4
Created November 6, 2016 14:02
Kankun plug gist for MacOS (OSX)
#!/usr/bin/python
import os
import socket
import sys
def encode_packet(data):
output = bytearray()
for i in range(0, len(data)):
tmpoutput = bytearray([0, data[i]])
var fs = require('fs');
var filePath = 'js/data/data.json';
var outputPath = 'sitemap.xml';
var date = new Date().toISOString();
var header = '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">\n';
var baseUrl = 'http://getfreestuff.co/';
fs.readFile(filePath, 'utf8', function(err, data){
var json = JSON.parse(data);
var urls = [];
@oscarmorrison
oscarmorrison / openWaffle.sh
Last active June 5, 2016 16:38
Open Waffle from Repository
# https://github.com/youUsername/repoName.git
# https://waffle.io/youUsername/repoName
url=$(git config --get remote.origin.url)
url=$( tr '[A-Z]' '[a-z]' <<< $url)
url=${url%.git}
url="${url/github.com/waffle.io}"
echo $url
open $url
@oscarmorrison
oscarmorrison / missing-image.html
Created June 4, 2016 03:38
html backup image
<img src="img/missing-image.png" onerror="javascript:this.src='img/default.png'">
@oscarmorrison
oscarmorrison / String Match.
Last active April 30, 2016 03:47
String Match. Match two strings with a tolerence
function matchString(stringOne, stringTwo, tolerance){
stringOne = stringOne.toLowerCase().replace(/ /g,'');
stringTwo = stringTwo.toLowerCase().replace(/ /g,'');
var minLen = Math.max(stringOne.length, stringTwo.length);
var bigLen = Math.min(stringOne.length, stringTwo.length);
for(var i = 0, count = 0; i < minLen; i++){
if(stringOne[i] === stringTwo[i]){
count++;
}
}