Skip to content

Instantly share code, notes, and snippets.

View kgn's full-sized avatar

David Keegan kgn

View GitHub Profile
@kgn
kgn / ZipDir.py
Created October 5, 2010 03:04
Python function to zip up a directory and preserve any symlinks and empty directories.
import os
import zipfile
def ZipDir(inputDir, outputZip):
'''Zip up a directory and preserve symlinks and empty directories'''
zipOut = zipfile.ZipFile(outputZip, 'w', compression=zipfile.ZIP_DEFLATED)
rootLen = len(os.path.dirname(inputDir))
def _ArchiveDirectory(parentDirectory):
contents = os.listdir(parentDirectory)
@kgn
kgn / AppReviews
Created June 9, 2015 23:02
App Reviews - Python script to retrieve App Store reviews and save them to a CSV file
#!/usr/bin/env python
try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen
import json
@kgn
kgn / gist:1558664
Created January 4, 2012 05:37
Animated NSTableView Scrolling
// Thanks to CuriousKea for getting this started!
// http://stackoverflow.com/a/8480325/239380
- (void)scrollRowToVisible:(NSInteger)rowIndex animate:(BOOL)animate{
if(animate){
NSRect rowRect = [self rectOfRow:rowIndex];
NSPoint scrollOrigin = rowRect.origin;
NSClipView *clipView = (NSClipView *)[self superview];
scrollOrigin.y += MAX(0, round((NSHeight(rowRect)-NSHeight(clipView.frame))*0.5f));
NSScrollView *scrollView = (NSScrollView *)[clipView superview];
@kgn
kgn / s3upload.swift
Created January 28, 2022 05:57
Simple function to upload files to S3 in Swift with no dependencies
import Foundation
import CryptoKit
extension String {
func hmac(key: String) -> String {
let secret = key.data(using: .utf8)!
let message = self.data(using: .utf8)!
var hmac = HMAC<Insecure.SHA1>(key: SymmetricKey(data: secret))
hmac.update(data: message)
@kgn
kgn / svg2png
Created October 12, 2021 04:32
Convert svg to png
import svg2img from 'svg2img';
module.exports = (req, res) => {
const url = req.query.url;
const width = req.query.width;
const height = req.query.height;
const size = Math.min(width, height);
svg2img(url, {width: size, height: size, preserveAspectRatio: true},
function(error, buffer) {
if (buffer) {
@kgn
kgn / svg2png.js
Created September 21, 2021 14:33
const svg2img = require('svg2img');
module.exports = (req, res) => {
svg2img(req.query.url, {width: req.query.width, height: req.query.height, preserveAspectRatio: true},
function(error, buffer) {
if (buffer) {
res.send(buffer);
}
});
};
@kgn
kgn / jquery.flipbook.js
Created November 29, 2010 07:22
jQuery plugin to display an animated image sequence.
//By David Keegan
//InScopeApps.com
//http://inscopeapps.com/demos/flipbook/
(function($){
$.fn.flipbook = function(options){
options = $.extend({
'start': 0, //start frame
'end': 100, //end frame, must be greater then start
'step': 1, //number of frames to step over while animating
enum Food: String {
case beef = "Beef"
case chicken = "Chicken"
case vegitarian = "Vegitarian"
case kids = "Kids"
}
protocol People {
var people: [Person] { get }
}
@kgn
kgn / End.swift
Last active August 19, 2019 05:58
for (i, table) in tables.enumerated() {
print("Table #\(i+1)")
print(table.people
.map{"\($0.name),\($0.food.rawValue)"}
.joined(separator: "\n")
)
}
protocol People {
var people: [Person] { get }
}
@_functionBuilder
struct PeopleBuilder {
static func buildBlock(_ people: People...) -> [Person] {
return people.reduce([], {$0+$1.people})
}
}