Skip to content

Instantly share code, notes, and snippets.

View JoshuaGross's full-sized avatar

Joshua Gross JoshuaGross

View GitHub Profile
UIPasteboard* pasteBoard = [UIPasteboard generalPasteboard];
[pasteBoard setString:@"any NSString"];
NSString* clipboard = [pasteBoard string];
require_once('Mail/mimeDecode.php');
$mail = file_get_contents($filename);
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$decoder = new Mail_mimeDecode($mail);
$structure = $decoder->decode($params);
@JoshuaGross
JoshuaGross / vim-sentences-one-line
Created February 21, 2012 00:17
Vim: collapse sentences into one line
%s/\([^.?!]\)\n/\1 /g
@JoshuaGross
JoshuaGross / file-ext-to-mime.js
Created July 12, 2012 17:32
Map file extension to mimetypes
// This method takes in one argument, a filename, and looks up its extension in the dictionary.
// If you want to do this in another language, use the bookmarklet below to regenerate a dictionary or array in whatever format you want.
//
// Written 2012 by Joshua Gross for SpanDeX, Inc. Do whatever you want with this.
//
// I used a bookmarklet to generate this mimeTypes dictionary
// Navigate to http://www.webmaster-toolkit.com/mime-types.shtml
// and use this bookmarklet:
// javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){ var mimeTypes = {}; $('div.content > div > table > tbody > tr').each(function (i, el) { var children
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl -L https://www.npmjs.org/install.sh | sh
@JoshuaGross
JoshuaGross / gist:7c2569935cb6e7aecc45
Created April 26, 2015 04:21
Test an echo server on the command-line with node
node -e "var client; (client = new require('net').Socket()).connect(7000, \"0.0.0.0\", function () { console.log(\"connected\"); client.on(\"data\", function (data) { console.log(\"Received:\" + data); client.destroy(); }); client.write(\"holla\"); });"
@JoshuaGross
JoshuaGross / normalize-json.sh
Last active December 11, 2015 02:09
Sort JSON to make it easier to diff two JSON blobs by normalizing whitespace, alphabetization of dictionaries.
# Install:
npm install -g sort-json
# Put this in your ~/.profile, and then:
# cat something.json | normalize_json
alias normalize_json="node -e 'var s = \"\"; process.stdin.on(\"data\", function (d) { s += d.toString(); }); process.stdin.resume(); process.on(\"exit\", function() { console.log(JSON.stringify(require(\"sort-json\")(JSON.parse(s)), null, 2)); });'"
@JoshuaGross
JoshuaGross / vimline.sh
Last active December 15, 2015 18:43
Open vim to a certain file, line, and (optionally) column
# https://gist.github.com/JoshuaGross/ad146e15c80ba7424ede
# Open vim to a certain file, line, and (optionally) column
function vimline {
col=$(echo $1 | awk '{split($0,a,":"); print a[3]}')
line=$(echo $1 | awk '{split($0,a,":"); print a[2]}')
file=$(echo $1 | awk '{split($0,a,":"); print a[1]}')
if [ -z "$col" ]; then
linecol="+$line"
else
linecol="+call cursor($line, $col)"
@JoshuaGross
JoshuaGross / SizeOfTablesPostgres.sql
Last active January 5, 2016 23:42
Size of all tables in a Postgres DB.
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM
pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
@JoshuaGross
JoshuaGross / SizeOfRelationsPostgres.sql
Last active January 5, 2016 23:46
Size of all relations (indices, tables, etc) in a Postgres DB.
SELECT
relname AS objectname,
relkind AS objecttype,
reltuples AS "#entries",
pg_size_pretty(relpages::bigint*8*1024) AS size
FROM pg_class
WHERE relpages >= 8
ORDER BY relpages DESC;