Skip to content

Instantly share code, notes, and snippets.

View jsjohnst's full-sized avatar

Jeremy Johnstone jsjohnst

View GitHub Profile
@jsjohnst
jsjohnst / if_elseif_else.php
Created December 15, 2011 03:09
Which is easier as far as code maintainability and readability goes?
<?php
if($http_code >= 200 && $http_code < 300) {
if($body == "foo") {
// do something
} else if($body == "bar") {
// get drunk
} else {
// do something else
}
switch(true) {
case $http_code >= 200 && $http_code < 300:
// success!
break;
case $http_code >= 500 && $http_code < 600:
// server errpr
break;
case $http_code == 403:
// denied
break;
@jsjohnst
jsjohnst / xmlwriter.java
Created December 9, 2011 03:23
The code needed to build an XML string properly in Java... Ugh!
import java.io.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
public class XMLWriter {
public static void main (String args[]) {
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>vc-build-version</key><string>1Y51</string>
<key>vc-build-revision</key><string>198959</string>
<key>id-validation-cert</key><string>http://static.ess.apple.com/identity/validation/cert-1.0.plist</string>
<key>id-initialize-validation</key><string>https://service2.ess.apple.com/WebObjects/TDIdentityService.woa/wa/initializeValidation</string>
<key>id-provision-phone-number</key><string>https://service2.ess.apple.com/WebObjects/TDIdentityService.woa/wa/provisionPhoneNumber</string>
<key>id-provision-ds-id</key><string>https://service.ess.apple.com/WebObjects/VCProfileService.woa/wa/idsProvisionEmails</string>
@jsjohnst
jsjohnst / mind_fuck.js
Created September 17, 2011 02:31
My entry into the WTF JS hall of fame... :)
Version #1...
$="co)(1";($)[+[]]+($)[+!+[]]+([![]]+[][[]])[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])
[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[!+[]+!+[]+!+[]+!+[]+!+[]]+($)[+[]]+(!![]+[])[+[]]+($)[+!+[]]+(!![]+[])
[+!+[]][($)[+[]]+($)[+!+[]]+([![]]+[][[]])[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])
[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[!+[]+!+[]+!+[]+!+[]+!+[]]+($)[+[]]+(!![]+[])[+[]]+($)[+!+[]]+(!![]+[])
[+!+[]]][($)[+[]]+($)[+!+[]]+([![]]+[][[]])[!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])
[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[!+[]+!+[]+!+[]+!+[]+!+[]]+($)[+[]]+(!![]+[])[+[]]+($)[+!+[]]+(!![]+[])
[+!+[]]]((![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]+(!![]+[])[+[]]+($)
[!+[]+!+[]+!+[]]+($)[!+[]+!+[]+!+[]+!+[]]+($)[!+[]+!+[]])();
@jsjohnst
jsjohnst / json_in_awk.txt
Created August 25, 2011 22:27
Terrible, but working JSON parser for flat JSON in already validated semantic form.
Prints out each key/value pair:
awk '{ gsub(/[{}]/, "", $0); n=split($0,a,","); for (i=1; i<=n; i++) if(length(k) > 0) { if(index(a[i], k) != 0) { split(a[i],b,":"); print b[2]; } } else { print a[i] } }'
Example input:
{"verified":false,"protected":false,"location":"San Francisco"}
Example output:
"verified":false
"protected":false
@jsjohnst
jsjohnst / example_output.png
Created May 13, 2011 17:10
Example of getting recommendations from LinkedIn JSAPI
example_output.png
@jsjohnst
jsjohnst / firewall_port.sh
Created May 4, 2011 21:52
Opening firewall ports on a Palm Pre via the command line
#!/bin/bash
luna-send -n 1 palm://com.palm.firewall/portCtrl '{ "label": "pdlportT_8
080", "protocol": "TCP", "port": 8080, "isDestinationPort": true, "isEnabled": true }'
@jsjohnst
jsjohnst / .vimrc
Created December 29, 2010 19:51
Sample .vimrc to solve one of the #vimgolf challenges
:set compatible
let @y=':g/./|s/{/(/|s/}/)/|s/\[\S$/{/|s/^]/}/|s/(\S$/{/|s/)\S$/}/^M'
let @z=':2g/./|s/(/[/|s/)/]/^M'
@jsjohnst
jsjohnst / comment_flag_in.css
Created December 27, 2010 05:45
Pure CSS (without extra HTML markup) comment speech bubbles for SquareSpace blogs.
.journal-comment-area-wrapper .comment .signature:before {
font-size: 10px;
content: '';
display: block;
height: 0;
width: 0;
border-right: 2em solid #666;
border-bottom: 2em solid #000;
border-bottom: 2em solid transparent;
position: absolute;