Skip to content

Instantly share code, notes, and snippets.

@kurtroberts
kurtroberts / reverse-proxy.js
Created December 24, 2013 18:10
For the first useful thing I ever built in node, I hacked together this reverse proxy script so that I could fiddle with front-end code on a remote website more easily. It sits between your computer and the remote site, checking first for files in a folder you specify, then trying a GET request against the site.
var http = require('http'),
path = require('path'),
fs = require('fs'),
localPath = "/PATH/TO/LOCAL/FOLDER/",
remoteServer = { host: 'www.example.com',
port: 80
},
mimeTypes = { 'js' : 'text/javascript',
'css' : 'text/css',
'html' : 'text/html',
@kurtroberts
kurtroberts / rg3bot.js
Created December 24, 2013 18:44
Get yourself banned from twitter in about 3 seconds. Cleaning out more old code that I will never need. This one was from the RP3 -> RG3 conversion.
var twitter = require('ntwitter');
var twit = new twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
twit.stream('statuses/filter', {'track': 'rgiii'}, function(stream) {
@kurtroberts
kurtroberts / lowercase_filenames.pl
Created December 24, 2013 19:43
For when sloppy coders can't keep their case straight. I never believed this possible, but after contracting with a firm who's name I will not mention for a team, I got back about 200 json files with randomly capitalized names. Despite being very clear we were deploying to an apache2 server on Linux, they tested on their case-insensitive Windows…
#!/usr/bin/perl -w
opendir DIR, ".";
my @files = grep { $_ ne '.' && $_ ne '..' } readdir DIR;
closedir DIR;
for $file (@files) {
my $lfile = lc($file);
if ($lfile ne $file) {
print $file . "\n";
@kurtroberts
kurtroberts / gist:a5c630792e786313e0e1
Last active July 3, 2018 14:54
When only the least elegant solution will do...
<?php
//I have made a lot of nice things with PHP. But this isn't one of them.
if (!function_exists('lets_confuse_strings_and_symbols')) {
function lets_confuse_strings_and_symbols ($funny_function_name) {
return eval($$funny_function_name);
}
}
@kurtroberts
kurtroberts / gist:5768cecc052145e8fc34
Created June 2, 2015 15:04
I remember when Project Managers would pay IA contractors to audit the content on a site, and they'd just give us back a spreadsheet full of links...
//Collecting links is a below-the-api job...
//(http://www.forbes.com/sites/anthonykosner/2015/02/04/google-cabs-and-uber-bots-will-challenge-jobs-below-the-api/)
var huntsman = require('huntsman'),
spider = huntsman.spider(),
fs = require('fs'),
out = fs.createWriteStream('example.com.csv');
spider.extensions = [
huntsman.extension( 'recurse' ), // load recurse extension & follow anchor links
@kurtroberts
kurtroberts / gist:ed26aa5a71cd784a153b
Created July 7, 2015 16:36
First exploration of my "N things about X" article-writing robot
var summary = require('node-tldr'),
sentiment = require('sentiment'),
opts = require('nomnom')
.option('url', {
abbr: 'u',
help: 'URL to summarize',
required: true
})
.parse();
summary.summarize(opts.url, function(result, failure) {
@kurtroberts
kurtroberts / gist:c7ffb93b0822c07508f3
Created July 7, 2015 19:06
Create a CSV file with some basic SEO evaluation
var huntsman = require('huntsman'),
spider = huntsman.spider(),
fs = require('fs'),
opts = require('nomnom')
.option('domain', {
abbr: 'd',
help: 'Domain to scan.',
required: true
})
.option('startUrl', {
@kurtroberts
kurtroberts / fortune500.txt
Last active June 7, 2019 19:08
Check a list of sites to see if they are Google Mobile friendly.
http://www.corporate.walmart.com/
http://www.exxonmobil.com/
http://www.chevron.com/
http://www.berkshirehathaway.com/
http://www.apple.com/
http://www.phillips66.com/
http://www.gm.com/
http://www.ford.com/
http://www.ge.com/
http://www.valero.com/
@kurtroberts
kurtroberts / test.js
Created October 13, 2015 17:26
I really thought at the level of abstraction we typically work (Node.js) the idea of "write combining" wasn't going to make a difference. I was wrong.
//To understand how I started down this rabbit hole, go here: http://mechanical-sympathy.blogspot.com/2011/07/write-combining.html
var iterations = parseInt(2147483647 / 128);
//Base case, no optimization
function runCaseOne () {
console.time('caseOne');
var i = iterations,
arrayA = [],
arrayB = [],
@kurtroberts
kurtroberts / integers-in-js.md
Last active July 3, 2018 14:53
Understanding Integers and Performance in JS

Understanding Integers and Performance in JS

This is just an interactive node session, not really a code snippet.

But it's pretty instructive.

Implicit Casting

kroberts-macpro:~ kroberts$ node
> 23|0