Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / linkedInLinksPlus.R
Created June 27, 2014 17:55
Grabs all LinkedIn urls from a Coursera forum thread. Perfect for the "Let's Connect!" threads.
require(XML)
require(stringr)
#
# Grabs all names and LinkedIn urls from a Coursera forum thread. Perfect for the "Let's Connect!" threads.
# Usage:
# 1. Open a Coursera forum thread, containing LinkedIn links.
# 2. Scroll all the way to the bottom of the page to load all posts in the thread.
# 3. Save the web page to an html file named post.htm.
# 4. Call linkedInLinks("post.htm")
@primaryobjects
primaryobjects / timer.R
Created July 8, 2014 01:52
Calculating the mean of a data table column in R (American Community Survey) and timing the result.
doLoop <- function(method, iterations = 1000) {
for (i in 1:iterations) {
method();
}
}
# Load csv file.
DT <- fread('https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Fss06pid.csv')
# Time option 2.
@primaryobjects
primaryobjects / loginimage.sh
Last active August 29, 2015 14:05
Linux Mint login background changer. Changes the background image on the Linux Mint theme login screen. To run automatically at each reboot, run this script as: sudo bash loginimage.sh -r. Put the command in /etc/rc.local
#!/bin/bash
appPath=/usr/share/login-image-changer
settingsPath=$appPath/settings.conf
rcLocalPath="/etc/rc.local"
scriptPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
runCommand="sudo bash \"$scriptPath/loginimage.sh\" -r"
settingsExists=0
install=0
uninstall=0
@primaryobjects
primaryobjects / bf_to_c
Last active August 29, 2015 14:13
BF to C Converter (source at https://github.com/matslina/bfoptimization). Change line 74 to convert your own BF code: ir_to_c(bf_to_ir("+++.")). Example output from this program https://ideone.com/z16KPJ.
from collections import namedtuple
# These map directly to the 8 regular brainfuck instructions. The
# exception is the offset parameter, which would be 0 in regular
# brainfuck, but can here indicate an offset from the current cell at
# which the operation should be applied.
Add = namedtuple('Add', ['x', 'offset'])
Sub = namedtuple('Sub', ['x', 'offset'])
Right = namedtuple('Right', ['x'])
Left = namedtuple('Left', ['x'])
@primaryobjects
primaryobjects / parser.js
Last active August 29, 2015 14:14
Javascript parser for STRIPS PDDL grammar parser from pegjs.org. This code parses the result of the pegjs grammar produced from the file grammar.txt https://gist.github.com/primaryobjects/22363e71112d716ea183 and returns a JSON object with the action operators, conditions, and effects.
/*
grammar.txt: saved from https://gist.github.com/primaryobjects/22363e71112d716ea183
domain.txt:
(define (domain random-domain)
(:requirements :strips :typing)
(:action op1
:parameters (?x1 ?x2 ?x3)
:precondition (and (S ?x1 ?x2) (R ?x3 ?x1))
:effect (and (S ?x2 ?x1) (S ?x1 ?x3) (not (R ?x3 ?x1))))
(:action op2
@primaryobjects
primaryobjects / app.js
Created February 24, 2015 03:15
Planning graph using the strips node.js library.
var strips = require('strips');
var util = require('util');
// Load the domain and problem.
strips.load('./domain-cake.pddl', './problem-cake.pddl', function(domain, problem) {
var S = [];
// S0 - 1 node per literal in initial state.
for (var i in problem.states[0].actions) {
var literal = problem.states[0].actions[i];
@primaryobjects
primaryobjects / run.bat
Created February 24, 2015 14:41
DOS batch file to launch a NodeWebKit app. NodeWebKit has a habit of occasionally immediately quitting when trying to launch it. This script times the launch and quit times, so if the app exits in less than 5 seconds, we re-launch the app, until we finally get a proper launch.
@echo off
:loop
:: Start timer.
@set /A _tic=%time:~0,2%*3600^
+%time:~3,1%*10*60^
+%time:~4,1%*60^
+%time:~6,1%*10^
+%time:~7,1% >nul
@primaryobjects
primaryobjects / deploy_node_site.txt
Last active August 29, 2015 14:16
4 easy steps to deploy a node.js web site to a Windows server.
1. Download and install node.js at http://nodejs.org/download/
2. Copy your node.js project files to C:\Users\YOUR_USERNAME\Documents\SITENAME
3. Open Windows Firewall port 80.
4. Open Windows Powershell and type:
$env:PORT = 80
cd C:\Users\YOUR_USERNAME\Documents\SITENAME
@primaryobjects
primaryobjects / minify.js
Last active August 29, 2015 14:16
3 Tools for Minifying Your Web Project
/*
html-minifier
https://www.npmjs.com/package/html-minifier
UglifyCSS
https://github.com/fmarcia/UglifyCSS
UglifyJS2
https://github.com/mishoo/UglifyJS2
@primaryobjects
primaryobjects / info.txt
Last active August 29, 2015 14:16
Razor Syntax for node.js views using Vash view engine.
Razor Syntax for node.js views
https://github.com/kirbysayshi/vash#syntax-example
Example Controller:
exports.page = function(req, res) {
res.render('page.vash', { name: 'John Doe', colors: [ 'red', 'green', 'blue' ] });
};
Example Views: