This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When using Polymorphism, you might define an abstract class to send a message like | |
// follows, then fully implement it several times in different classes. | |
abstract class BaseMessage | |
public void setMessageText messageText | |
@messageText = messageText | |
end | |
public void send; | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "securerandom" | |
length = 24 | |
if ARGV[0] | |
length = ARGV[0].to_i | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "httparty" | |
data_index_url = "http://www.police.uk/data" | |
data_index_response = HTTParty.get data_index_url | |
if data_index_response.code != 200 | |
throw "Fetching URL '#{data_index_url}' failed: '#{data_index_response.code}', '#{data_index_response.message}'" | |
end | |
zip_match_regex = /\/\/policeuk.s3.amazonaws.com\/frontend\/crime-data\/([0-9]+)-([0-9]+)\/[0-9]+-[0-9]+-([a-z-]+)-([a-z]+).zip/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'httparty' | |
require 'active_support/time' | |
require 'sinatra' | |
def prom_string days_time | |
headers = {"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"} | |
response = HTTParty.get "http://www.bbc.co.uk/proms/whats-on/2013/print-season", :headers => headers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'nokogiri' | |
require 'json' | |
pages = 1..64 | |
def get_page page | |
$stderr.puts "get_page #{page}" | |
return HTTParty.get("http://www.charitychoice.co.uk/charities/england/#{page}?onlinedonations=1") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 5 | |
b = 10 | |
if a < b | |
puts "5 is less than 10" | |
else | |
puts "5 is not less than 10" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <strings.h> | |
#include <string.h> | |
#include <inttypes.h> | |
#include <math.h> | |
#include <gmp.h> | |
// http://projecteuler.net/problem=15 | |
// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (m *MersenneTwister) Urand32() uint32 { | |
if m.index == 0 { | |
m.generate_numbers() | |
} | |
y := m.State[m.index] | |
y = y ^ (y >> 11) // | |
y = y ^ ((y << 7) & 2636928640) // | |
y = y ^ ((y << 15) & 4022730752) // | |
y = y ^ (y >> 18) // "y XOR leftmost 14 bits of y" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Serial code | |
#include "stdhapr.h" // https://gist.github.com/46bit/8890761 | |
#include "lpc17xx_timer.h" | |
TIM_TIMERCFG_Type TIM_ConfigStruct; | |
TIM_MATCHCFG_Type TIM_MatchConfigStruct; | |
#define SEG7_0 0b11111100 | |
#define SEG7_1 0b01100000 | |
#define SEG7_2 0b11011010 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "lpc17xx_i2c.h" | |
#include "lpc17xx_pinsel.h" | |
#include "lpc17xx_uart.h" | |
#include "lpc17xx_gpio.h" | |
#include "lpc17xx_nvic.h" | |
#include "lpc17xx_gpdma.h" | |
#include "lpc17xx_adc.h" | |
#include "lpc17xx_dac.h" | |
#include <math.h> | |
#include <string.h> |