Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# Script to convert the Learn Prolog Now! online HTML edition to a PDF.
require 'nokogiri'
require 'open-uri'
require 'pdfkit'
class HTMLBook
attr_reader :content, :footer
@basicxman
basicxman / gist:1136141
Created August 10, 2011 04:44
Poor-man's script for GeekTool -
df -h
echo
ps auxc | head -n 6
echo
echo "Network information:"
netstat -s -p tcp | sed -n '2p;11p;28p;29p;30p;44p' | tr -d "\t"
echo
cat ~/weather.txt
# Screenshot
@basicxman
basicxman / football_one.sh
Created August 7, 2011 06:00
Code Kata in Bash or "I get crazy at 2AM"
#!/bin/bash
# http://codekata.pragprog.com/2007/01/kata_four_data_.html
awk '{print (($7 - $9) < 0 ? -($7 - $9) : $7 - $9) " " $2}' football.dat | grep -P "[A-Za-z_]{2,}" | sort -n | head -n 1 | awk '{print $2}'
$ ruby weather_split_vs_scan_benchmarks.rb
user system total real
Using split 0.320000 0.010000 0.330000 ( 0.330723)
Using scan 0.230000 0.020000 0.250000 ( 0.239557)
@basicxman
basicxman / google_docs_cpp_monitor.rb
Created August 1, 2011 03:07
Monitors a public Google Docs page containing source code and compiles it in C++ every five seconds. Primitive CI.
#!/usr/bin/env ruby
# Andrew Horsman
# Monitors a Google Docs page and continuously compiles the text with Clang++.
require 'net/http'
require 'open-uri'
class Downloader
def initialize(source_url)
CPP = clang++
OUTPUT = dijkstra
CPPFLAGS = -stdlib=libc++ \
-IGraph \
-IDataStructures \
-o $(OUTPUT)
INPUTFILES = Graph/DijkstraPQ.cpp Graph/Graph.cpp DataStructures/PriorityQueue.cpp
main:
$(CPP) $(CPPFLAGS) $(INPUTFILES)
#include "Graph.h"
#include "PriorityQueue.h"
void PrintPath(int start, int end, int *parents, int *distance) {
cout << end << " (" << distance[end] << "): ";
int a = start;
int b = end;
while (a != b) {
cout << b << " -> ";
b = parents[b];
#!/usr/bin/env ruby
loop do
if rand < 0.5
`say herp derp`
else
`say trololololol`
end
end
# If you disturb me while studying, your ears are declared forfeit to this script.
2 ~$ rvm use 1.8.7
Using /Users/basicxman/.rvm/gems/ruby-1.8.7-p330
3 ~$ git clone git://github.com/mojombo/chronic.git && cd chronic && rake test
Cloning into chronic...
remote: Counting objects: 2059, done.
remote: Compressing objects: 100% (957/957), done.
remote: Total 2059 (delta 1344), reused 1782 (delta 1083)
Receiving objects: 100% (2059/2059), 277.02 KiB, done.
Resolving deltas: 100% (1344/1344), done.
/Users/basicxman/.rvm/rubies/ruby-1.8.7-p330/bin/ruby -I"lib:lib:test" -I"/Users/basicxman/.rvm/gems/ruby-1.8.7-p330/gems/rake-0.9.2/lib" "/Users/basicxman/.rvm/gems/ruby-1.8.7-p330/gems/rake-0.9.2/lib/rake/rake_test_loader.rb" "test/**/test_*.rb"
/*
* Perform a single rotation in the given direction around a given root
* tree and return the new root.
* 3 4
* \ / \
* 4 ==> 3 5
* \
* 5
*
* The comments will follow with an example of performing a left rotation