Skip to content

Instantly share code, notes, and snippets.

View jonahgeorge's full-sized avatar

Jonah George jonahgeorge

View GitHub Profile
@jonahgeorge
jonahgeorge / cli_args.c
Last active December 24, 2015 05:18
Command Line Options
#include <iostream>
#include <cstring>
using namespace std;
int main (int argc, char *argv[]) {
cout << "Number of args: " << argc << endl;
cout << "Name of program: " << argv[0] << endl;
if (argc > 1) {
cout << "2nd argument: " << argv[1] << endl;
@jonahgeorge
jonahgeorge / script.rb
Created January 11, 2014 00:44
Ruby Script for appending pdfs with Prawn
#!/usr/bin/ruby
require 'json'
require 'prawn'
raw = File.open("data.json")
json = JSON.parse(raw.read)
Prawn::Document.generate("result.pdf", {:page_size => 'A4', :skip_page_creation => true}) do |pdf|
json["teams"].each do |team|
@jonahgeorge
jonahgeorge / script.sh
Created March 14, 2014 07:07
Tcpdump Examples
# Captures one packet and writes it to output.pcap
sudo tcpdump -I -P -i en0 -w output.pcap -c 1
# Converts output.pcap to a more human-friendly format
tshark -r output.pcap -V
@jonahgeorge
jonahgeorge / upload.go
Created April 1, 2014 18:42
Go Handle File Upload
package main
import (
"fmt"
"github.com/gorilla/mux"
"io/ioutil"
"log"
"net/http"
)
@jonahgeorge
jonahgeorge / model_generator.rb
Last active June 14, 2016 18:08
Generates PHP ActiveRecord class files for the #MECOP system
require 'active_support/all'
require 'mysql2'
require 'erb'
def get_primary_key(client, table)
query = "SHOW INDEX FROM #{table} WHERE Key_name = 'PRIMARY';"
result = client.query(query).first
result["Column_name"]
end
@jonahgeorge
jonahgeorge / echo_server.c
Last active August 29, 2015 14:11
Sample Programs using the Win32 API for CS344-001 Term Essay
/**
* Author: Jonah George
* Date: December 11, 2014
* Description: A simple echo server using the Winsock2 Api
* References: http://msdn.microsoft.com/en-us/library/windows/desktop/ms737593(v=vs.85).aspx
*/
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
@jonahgeorge
jonahgeorge / project4.py
Created March 5, 2015 03:11
Project 4 PULP
import csv
import math
from pulp import *
def linear_trend(x0, x1, d):
return x0 - (x1 * d)
def seasonal_pattern(x2, x3, d):
return x2 * math.cos( (2 * math.pi * d) / 365.25) - x3 * math.sin( (2 * math.pi * d) / 565.25 )
@jonahgeorge
jonahgeorge / problem1.go
Last active August 29, 2015 14:19
Project Euler Problems in Go
package main
func Problem1() int {
sum := 0
for i := 0; i < 1000; i++ {
if i % 3 == 0 || i % 5 == 0 {
sum += i
}
}
return sum
SELECT "resources".*
FROM "resources"
INNER JOIN "resources_tags" ON "resources_tags"."resource_id" = "resources"."id"
INNER JOIN "tags" ON "tags"."id" = "resources_tags"."tag_id"
WHERE ("tags"."id" IN (4,16)
AND (SELECT count(*) FROM "tags" WHERE "tags"."id" IN(4,16)) = 2)
GROUP BY "resources"."id"
ORDER BY "resources"."name" ASC
-- Ryan's new method
@jonahgeorge
jonahgeorge / test_gen.rb
Created September 19, 2015 23:18
Generates Capybara tests for the rails_admin index page for all models.
models = Dir.glob("*.rb")
def spec(model)
template = <<-END
scenario "#{model}" do
visit rails_admin.index_path(model_name: "#{model}")
page.status_code.must_equal 200
page.assert_current_path rails_admin.index_path(model_name: "#{model}")
end