Skip to content

Instantly share code, notes, and snippets.

@robcolburn
robcolburn / getQuery.js
Created May 3, 2012 20:11
Parse query string parameters
function getQuery(s) {
var query = {}, i = s.indexOf('?');
if (i != -1) {
s.substr(i+1).replace(/\+/g, ' ').replace(/([^&;=]+)=?([^&;]*)/g, function (m, k, v) {
query[decodeURIComponent(k)] = decodeURIComponent(v);
});
}
return query;
}
//_GET = getQuery(location.href);
<a href="javascript:foo()">foo</a>
<script>
function foo() {
function allDone () {
return 'sweet, declaration at the beginning.'
}
'set a break here';
'check out the scope variables';
@robcolburn
robcolburn / custom-tweetbox.html
Created May 31, 2012 16:51
How to make custom tweetboxes
<div>
<h1>Tweetbox</h1>
<form id="my-tweetbox">
<p><textarea name="tweet">Write your tweet...</textarea></p>
<p><input type="submit" name="submit" value="Tweet!" /></p>
</form>
</div>
<div>
<h1>County Tweetbox</h1>
@robcolburn
robcolburn / gist:2919562
Created June 12, 2012 19:22
How to open only some urls in WebView
/*
From @craigpfau - http://craigpfau.com/2012/02/phonegap-ios-uiwebview-and-safari-app-links/
To just enable UIWebView for the single URL I used this code [projectFolder > Classes > MainViewController.m]
*/
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = request.URL;
if ([url.absoluteString rangeOfString:@"URLToOpenInUIWebView.com"].location != NSNotFound) {
return YES;
[2012-06-13 09-35-13-28] Log (Exception,High): System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.Exception: Could not connect to port 62078
at iMobileDeviceSharp.Discovery.USB.UsbmuxDevice.<>c__DisplayClass1.<ConnectAsync>b__0(Task connectTask)
at System.Threading.Tasks.Task.<>c__DisplayClasse`1.<ContinueWith>b__d()
at System.Threading.Tasks.Task`1.InvokeFuture(Object futureAsObj)
at System.Threading.Tasks.Tas
@robcolburn
robcolburn / round_percents.js
Last active January 13, 2020 12:05
Rounding of complementary percentages
/*!
* Given a set of numeric values, returns a set of integer percents
*
* Algorithm defined by Rahul Narain, translated to JavaScript.
* http://math.stackexchange.com/questions/183476/rounding-of-complementary-percentages#186225
*
* > round_percents([20.5, 79.5])
* [21, 79]
* > round_percents([24.8, 25.2, 0.5, 49.5])
* [25, 25, 1, 49]
@robcolburn
robcolburn / Tasker.js
Created November 14, 2012 22:25
Tasking jobs, will catch-up, get back on track
function Tasker () {
this.tasks = [];
this.wait();
}
Tasker.prototype = {
resolution: 1000,
timeoutID: 0,
isWaiting: false,
tasks: [],
add: function (name, perform, interval) {
@robcolburn
robcolburn / getScript.js
Last active December 10, 2015 01:09 — forked from anonymous/getScript.js
How jQuery.getScript should work!
function getScript (src, callback) {
var scripts = document.getElementsByTagName('script');
var script = document.createElement("script");
var once = true;
script.async = "async";
script.type = "text/javascript";
script.src = src;
script.onload = script.onreadystatechange = function () {
if (once && (!script.readyState || /loaded|complete/.test(script.readyState))) {
once = false;
@robcolburn
robcolburn / textarea.html
Created February 27, 2013 21:15
Just a text area
<style>html,body,textarea{margin:0;padding:0;border:0;width:100%;height:100%}</style>
<textarea></textarea>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.1/lodash.min.js"></script>
@robcolburn
robcolburn / urldiff.sh
Created June 4, 2013 18:54
Bash function to compare two urls
#urldiff http://www.google.com http://www.yahoo.com
function urldiff () {
local file
local files=""
for url in "$@"
do
file="urldiff-"${url//[^a-zA-Z0-9]/}
files=$files" "$file
echo "downloading $url > $file"
lwp-request -m 'GET' $url > $file