Skip to content

Instantly share code, notes, and snippets.

View oscarmorrison's full-sized avatar

Oscar Morrison oscarmorrison

View GitHub Profile
@oscarmorrison
oscarmorrison / Assignment 1 - Arduino Code
Created February 18, 2015 04:30
Assignment 1 - Arduino Code
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{
'1','2','3','A' }
,
{
'4','5','6','B' }
@oscarmorrison
oscarmorrison / blue_color_shade.js
Created April 23, 2015 00:08
Creates a shade of blue over supplied range
var numbers = [] //Array of numbers
var range = 100 // Maximum number
for (var i = 0; i < range; i++) {
numbers.push(Math.round(Math.random()*range));
}
blue_color_shade = function (range,number) {
var ratio = 255/range;
var shade = Math.round(number*ratio).toString(16)
@oscarmorrison
oscarmorrison / gist:0513198d0a305ddb0c98
Created April 27, 2015 20:17
Change color shade (using Blue value)
change_color = function(color){
var color = "#03ffc5"
var num = parseInt(color,16)
var num = parseInt(color.slice(color.length-2,color.length),16);
num = num + 50;
if(num>255){num = num-255;}
return color.slice(0,color.length-2)+num.toString(16)
}
@oscarmorrison
oscarmorrison / gist:80a448f266d89508bd6f
Last active August 29, 2015 14:20
Parse objects from PFQuery and Store only objects != current user
var usernames = [PFUser]()
var currentUser = PFUser.currentUser()
override func viewDidLoad() {
super.viewDidLoad()
var query = PFUser.query()
query?.findObjectsInBackgroundWithBlock({ (objects, error: NSError?) -> Void in
if error == nil{
for username in objects as Array!{
if(self.currentUser?.objectId != username.objectId){
@oscarmorrison
oscarmorrison / gist:4c9b156ec3f1c4d9d0c2
Created June 28, 2015 12:29
String to Int/Double/Float
var intString = "10"
var numberInt = intString.toInt()
var numberString = "10.1"
var numberDouble = (numberString as NSString).doubleValue
var numberFloat = NSString(string: numberString).floatValue
@oscarmorrison
oscarmorrison / brute_search.rb
Created September 6, 2015 06:07
Brute Force String Pattern matching in Ruby
sentence = "soijasdoijasdiojfuhfuhsdfhoscaroijasdoijasdijd"
n = sentence.length
key = "oscar"
l = key.length
i = 0
while i < n do
j = 0
puts sentence[i]
@oscarmorrison
oscarmorrison / TimeinWords.rb
Created September 12, 2015 07:37
Time in Words (Ruby)
def get_word(num)
teen = "teen"
case num
when 0; return "o' clock"
when 1; return "one"
when 2; return "two"
when 3; return "three"
when 4; return "four"
when 5; return "five"
when 6; return "six"
@oscarmorrison
oscarmorrison / getDate.js
Created November 1, 2015 23:41
Javascript get current date
//"YYYY-MM-DD hh:mm"
function zeroFill(i){
return (i<10 ? '0' : '') + i;
}
var getDate = function(){
var d = new Date();
var year = d.getFullYear();
var month = zeroFill(d.getMonth())
var day = zeroFill(d.getDate())
import subprocess
raw_location = subprocess.check_output("whereami", shell=False)
raw_location = raw_location.split()
lat = raw_location[1]
lon = raw_location[3]
hashtag = "#latlon"+lat+"__"+lon
command = "echo "+ "\'" + hashtag + "\' | pbcopy"
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
p.stdin.write(hashtag)
p.stdin.close()
@oscarmorrison
oscarmorrison / Return first Image from HTML Content
Last active February 7, 2016 21:01
Return first Image from HTML Content
var getFristImage = function(content) {
var el = document.createElement( 'html' );
el.innerHTML = content;
return el.getElementsByTagName( 'img' )[0].src;;
};