Skip to content

Instantly share code, notes, and snippets.

View marcuswestin's full-sized avatar

Marcus Westin marcuswestin

  • New York
View GitHub Profile
@marcuswestin
marcuswestin / sql.js
Created February 5, 2013 17:42
javascript to generate sql strings with appropriately named aliased for each selected property.
function selectFrom(table, props) {
return 'SELECT ' + joinProperties(props) + ' FROM ' + table + '\n'
function joinProperties(props) {
return ' '+map(props, function(rawName, prettyName) {
return rawName+' as '+prettyName
}).join(', ')+' '
}
}
selectFrom('person p', {
@marcuswestin
marcuswestin / gist:4597946
Last active December 11, 2015 11:59
Steps to delete s3 buckets (along with their contents)
# Install perl s3 library
sudo cpan Net::Amazon::S3
# Grab script
curl https://gist.github.com/marcuswestin/4597941/raw/delete-s3-bucket.pl > ./delete-s3-bucket.pl
# Run script
perl ./delete-s3-bucket.pl --access-key-id=AWS_ACCESS_KEY_ID --secret-access-key=AWS_ACCESS_KEY_SECRET --bucket=BUCKET_NAME
#!/usr/bin/perl
# Copyright (c) 2010 Jonathan Kamens.
# Released under the GNU General Public License, Version 3.
# See <http://www.gnu.org/licenses/>.
# $Id: delete-s3-bucket.pl,v 1.5 2010/10/26 14:11:09 jik Exp $
# Deleting an Amazon S3 bucket is hard.
#
@marcuswestin
marcuswestin / gist:4505623
Created January 10, 2013 20:44
Programmatically blur the currently focused input field inside of a UIWebVIew
- (void) blur:(UIWebView*)webView {
[self findAndResignFirstResponder:webView];
}
- (bool) findAndResignFirstResponder:(UIView*)view {
if ([view isFirstResponder]) {
[view resignFirstResponder];
return YES;
}
for (UIView* subview in [view subviews]) {
@marcuswestin
marcuswestin / gist:4497824
Created January 9, 2013 23:02
Hide the keyboard in iOS, no matter what view focus currently
- (void) hideKeyboard {
UITextView* view = [[UITextView alloc] initWithFrame:CGRectMake(0,0,0,0)];
[webView addSubview:view];
[view becomeFirstResponder];
[view resignFirstResponder];
}
@marcuswestin
marcuswestin / gist:4497062
Created January 9, 2013 21:20
Remove the "next/prev/done" bar from UIWebView keyboards.
- (void)keyboardWillShow:(NSNotification *)notification {
[self performSelector:@selector(removeWebViewKeyboardBar) withObject:nil afterDelay:0];
}
- (void)removeWebViewKeyboardBar {
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
@marcuswestin
marcuswestin / has.js
Created October 16, 2012 20:04
Deep check that an object has a given set of properties and values
function has(obj, props) {
each(props, function(propsVal, key) {
var objVal = obj[key]
if (propsVal == null) { return objVal === propsVal }
else if (isArray(propsVal) || typeof propsVal == 'object') { has(objVal, propsVal) }
else {
if (objVal != propsVal) { throw new Error('has: '+objVal+' != '+propsVal) }
}
})
}
@marcuswestin
marcuswestin / tinyTest.js
Created October 14, 2012 05:04
Tiny testing framework for the browser - inspired by mocha
module.exports = {
// Setup & Run
describe:describe,
then:then,
run:run,
// Assertion utils
is:is,
// DOM utils
tap:tap,
waitFor:waitFor
@marcuswestin
marcuswestin / isTouch.js
Created October 14, 2012 04:51
Is current browser a touch browser?
var isTouch
try { document.createEvent("TouchEvent"); isTouch = ('ontouchstart' in window) }
catch (e) { isTouch = false }
@marcuswestin
marcuswestin / lights.html
Created October 7, 2012 06:17
In "Notes on the Synthesis of Form" Christopher Alexander describes a thought experiment of light bulbs turning on and off. This script implements that thought experiment.
<!DOCTYPE html>
<html><head>
<style>
.light { position:absolute; border-radius:5px; background:black; }
.light.on { background:yellow; }
</style>
</head><body>
<div id="lights"></div>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>