Skip to content

Instantly share code, notes, and snippets.

View djmckee's full-sized avatar

Dylan McKee djmckee

View GitHub Profile
@djmckee
djmckee / gist:9027479499f8e5401418aac7acbe4e9c
Created June 11, 2016 12:41
Verifying that +dylanm is my blockchain ID. https://onename.com/dylanm
Verifying that +dylanm is my blockchain ID. https://onename.com/dylanm
int[] array = {1, 2, 2, 2, 3};
// The number you're counting occurrences of...
int number = 2;
// The number of times it occurs
int count = 0;
for (int i: array) {
if (i == number) {
int[] array = {10, 20};
int total = 0;
for (int i : array) {
total = total + i;
}
double average = (double)(total/array.length);
System.out.println("The average is: " + average + " :~)");
@djmckee
djmckee / GrouponApi.swift
Created October 30, 2015 09:22
A Swift Groupon API Wrapper, using NSURLSession (ideal for use on iOS or watchOS)
//
// GrouponApi.swift
// Munchies
//
// Created by Dylan McKee on 13/07/2015.
// Copyright (c) 2015 djmckee. All rights reserved.
//
import Foundation
import CoreLocation
@djmckee
djmckee / label-to-placeholder.js
Created July 24, 2015 22:52
A simple bit of Javascript (using jQuery) to fill in form input/textarea placeholder text from associated label tags - perfect for use in Django forms.
$("label").each(function (index) {
// get the 'for' value...
var forValue = $(this).attr('for');
// get the inner text...
var labelContent = $(this).text();
// remove trailing ':' from inner text...
if (labelContent.charAt(labelContent.length - 1) == ':') {
labelContent = labelContent.substring(0, labelContent.length - 1);
@djmckee
djmckee / keywords.py
Created July 22, 2015 22:45
Comma seperated Python keywords via the topia.termextract library (https://pypi.python.org/pypi/topia.termextract/)
# Requires https://pypi.python.org/pypi/topia.termextract/
from topia.termextract import extract
def generate_keyword_tags(string):
# instantiate our termextract instance
extractor = extract.TermExtractor()
# for keyword tags, we only care about the first 20 it picks out...
tags = extractor.tagger(string)[:20]
@djmckee
djmckee / NSDate+JSONDate.swift
Created July 6, 2015 16:16
An NSDate category written in swift to return the date in the form of a JSON date string.
import Foundation
extension NSDate {
func jsonDate() -> String {
let dateFormatter = NSDateFormatter()
// JSON Date fromat from http://gistpages.com/2015/05/21/convert_nsdate_to_json_date_format
dateFormatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'"
return String(dateFormatter.stringFromDate(self))
@djmckee
djmckee / keybase.md
Created June 3, 2015 09:50
it's me!

Keybase proof

I hereby claim:

  • I am djmckee on github.
  • I am djmckee (https://keybase.io/djmckee) on keybase.
  • I have a public key whose fingerprint is E1EB 9E97 2289 6D6B E5A6 8355 8FF2 24E2 8960 F026

To claim this, I am signing this object:

@djmckee
djmckee / UIColor+RGBColor.swift
Last active August 29, 2015 14:21
A Swift extension to convert a String containing an RGB Colour representation (like rgb(255, 255, 255)) to a UIColor instance (which it returns).
import Foundation
import UIKit
extension UIColor {
// A factory method to take an rgb colour string ("rgb(255,255,255)") and return a UIColor object.
class func colorFromRGBString(string: String) -> UIColor {
// create mutable copy...
var rgbString = string
@djmckee
djmckee / String+Contains.swift
Created April 3, 2015 13:42
String+Contains in Swift
import Foundation
extension String {
// check if the string contains otherString, return accordingly.
func contains(otherString:String!) -> Bool {
if self.rangeOfString(otherString) != nil{
return true
} else {
return false