Skip to content

Instantly share code, notes, and snippets.

View jmcph4's full-sized avatar

Jack McPherson jmcph4

View GitHub Profile
@jmcph4
jmcph4 / pythagoras.cpp
Created June 18, 2013 21:25
A small C++ program that generates pythagorean triplets, taking two integers as inputs. Compiled with GCC G++ 4.6.2.
#include <cstdlib>
#include <iostream>
using namespace std;
int triplet(int m, int n)
{
int a = (m * m) - (n * n);
int b = 2 * m * n;
int c = (m * m) + (n * n);
int triplet[3] = {a,b,c};
@jmcph4
jmcph4 / villages.cpp
Created September 26, 2013 02:52
A very simple program which shows the evolution of a village. Just use Excel, it's better.
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define POPULATION_DENSITY 10
#define GAME_LENGTH 10
class village
{
@jmcph4
jmcph4 / autocorrelate.cpp
Last active August 29, 2015 14:06
A small C++ program that performs an autocorrelation of a given dataset. Tested using http://www.itl.nist.gov/div898/handbook/eda/section4/eda4251.htm
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
std::vector<std::string> tokenise_csv_line(std::istream& str)
{
std::vector<std::string> result;
std::string line;
@jmcph4
jmcph4 / bloomberg_headlines.py
Created November 16, 2014 06:21
A small Python script that retrieves headlines from Bloomberg and counts the number of occurrences of a given keyword.
from bs4 import BeautifulSoup
import urllib2
def get_headlines():
url = "http://www.bloomberg.com/quickview"
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)
headlines = {}
for link in soup.find_all('a', class_="q story_link black"):
#include <iostream>
#include <vector>
// https://upload.wikimedia.org/wikipedia/en/7/76/Busy_Beaver_1.JPG
class Turing
{
public:
std::vector<bool> tape; // our tape, with an alphabet of {0,1}
int state; // the machine's current state
#include <iostream>
unsigned int A(unsigned int m, unsigned int n)
{
// std::cout << "A(" << m << "," << n << ")" << std::endl;
if(m == 0)
{
return n + 1;
}
@jmcph4
jmcph4 / rust_ecosystem.md
Created January 21, 2015 11:03
A curated list of Rust libraries, tools, projects, and more.

The Rust Ecosystem


A curated list of Rust libraries, tools, projects, etc.

Rust

The actual language.

Rust is located at rust-lang/rust.

@jmcph4
jmcph4 / pointers.cpp
Created January 22, 2015 23:03
Fun in the Sun with...pointers! *queue game show music from 80s*
#include <iostream>
int main(void)
{
int i = 37;
float f = i;
float g = *(float*)&i;
int* j = &i;
int* k = j;
int l = *j;
@jmcph4
jmcph4 / lol.rb
Created March 6, 2015 07:02
Basic proof-of-concept code for a League of Legends team analyser.
require 'rubygems'
require 'json'
require 'open-uri'
API_KEY = "INSERT_API_KEY_HERE"
#API_ROOT = "https://oce.api.pvp.net/api/lol/oce/v1.3/"
def pull(id, type)
if id != nil
case type
@jmcph4
jmcph4 / rt_today.py
Created March 11, 2015 07:21
Crawls RT's newsline for the current date using Beautiful Soup 4 and prints to the console.
from bs4 import BeautifulSoup
import urllib2
from StringIO import StringIO
import gzip
import time
url = "http://rt.com/news/line/"+time.strftime("%Y-%m-%d")
html_doc = urllib2.urlopen(url).read()
# Thanks to https://stackoverflow.com/questions/22004093/python-beautifulsoup-picking-webpages-same-codes-working-on-and-off#answer-22004440