Skip to content

Instantly share code, notes, and snippets.

View oscarmorrison's full-sized avatar

Oscar Morrison oscarmorrison

View GitHub Profile
@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 / 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;
})
}
#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 / 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
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.4.2/d3.min.js"></script>
<script>
var data = [4,8,15,16,23,42];
</script>
<style type="text/css">
@oscarmorrison
oscarmorrison / validateEmail.js
Last active May 27, 2017 06:38
ES6 email validation
// regex from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
const EMAIL_REGEX = /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-?\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
const validateEmail = email => {
return email
&& email.length < 255
&& EMAIL_REGEX.test(email);
};
export default validateEmail;
@oscarmorrison
oscarmorrison / _readme.md
Created May 26, 2017 16:13 — forked from hew/_readme.md
Operator Mono w/ Italics on OSX VIm

Operator Mono w/ Italics on OSX Vim

@oscarmorrison
oscarmorrison / getParamsFromSearchURL.js
Last active July 6, 2017 20:35
Get params from search url
const getParamsFromSearchURL = url => url.slice(1).split('&').reduce((params, pairs) => {
const [key, value] = pairs.split('=');
key && value && (params[key] = getValue(value));
return params;
}, {});
// this parses foo=true -> make true a bool, not a string
const getValue = value => {
value = decodeURIComponent(value);
try {
@oscarmorrison
oscarmorrison / d3Importer.js
Last active March 6, 2024 12:50
Modularly import only the D3.js modules you require
import { line, curve, curveCatmullRom } from "d3-shape";
import { scaleTime, scaleLinear } from "d3-scale";
import { axisBottom, axisLeft } from 'd3-axis';
import { timeParse, isoFormat } from "d3-time-format";
import { select } from "d3-selection";
import { extent, max, min } from "d3-array";
export default {
line: line,
scaleTime: scaleTime,
@oscarmorrison
oscarmorrison / heroku set .env .sh
Created July 29, 2017 17:32
Set you local config variables for remote heroku
heroku config:set `cat .env`