Skip to content

Instantly share code, notes, and snippets.

@tom-galvin
tom-galvin / dbgprint.h
Last active August 29, 2015 14:05
C macros for printing debug information
/* Defines macros tor printing debug information.
* To enable debug messages, #define DEBUG.
* To change the level, define DBG_PLEVEL to a level which
* is the minimum urgency that shall be printed.
*
* https://gist.github.com/Quackmatic/312e77a8df62bf731385
*/
#ifndef DBG_H
#define DBG_H
@tom-galvin
tom-galvin / vector2.c
Created August 15, 2014 20:57
C vector2 code
/* Quackmatic 2014
* https://github.com/Quackmatic
*/
#include <math.h>
#include "vector2.h"
vec2 vec_add(vec2 v1, vec2 v2)
{
vec2 value = { v1.x + v2.x, v1.y + v2.y };
@tom-galvin
tom-galvin / c175h.c
Created August 15, 2014 21:14
DailyProgrammer Challenge #175h Solution (Hall of Mirror[])
/* Vector2 code at https://gist.github.com/Quackmatic/8f904e2f0cb7d144c0b7
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include "vector2.h"
@tom-galvin
tom-galvin / c-cell.rb
Created August 18, 2014 08:55
DailyProgrammer Challenge #176e Solution (Spreadsheet Developer pt. 1: Cell Selection)
def alpha_to_num(str, col=0)
unless str.nil? || str.empty?
return (alpha_to_num(str.slice(0, str.length - 1), col + 1)) * 26 +
"abcdefghijklmnopqrstuvwxyz".index(str.downcase[str.length - 1]) + (col > 1 ? 1 : col)
else
0
end
end
def cell_coords(str)
@tom-galvin
tom-galvin / average-speed-cameras.txt
Last active August 29, 2015 14:06
DailyProgrammer #181i Input
This file has been truncated, but you can view the full file.
Speed limit is 60.00 mph.
Speed camera number 1 is 0 metres down the motorway.
Speed camera number 2 is 580 metres down the motorway.
Speed camera number 3 is 900 metres down the motorway.
Speed camera number 4 is 1390 metres down the motorway.
Speed camera number 5 is 1885 metres down the motorway.
Start of log for camera 1.
Vehicle PV50 CAN passed camera 1 at 05:33:26.
Vehicle W867 BRO passed camera 1 at 05:33:29.
Vehicle KQ63 ARU passed camera 1 at 05:33:38.
@tom-galvin
tom-galvin / average-speed-cameras-output.txt
Last active August 29, 2015 14:06
DailyProgrammer #181i Output
Vehicle M655 LLN broke the speed limit by 0.43 mph.
Vehicle U721 MXB broke the speed limit by 0.28 mph.
Vehicle H732 SKY broke the speed limit by 3.88 mph.
Vehicle 12 SM broke the speed limit by 0.98 mph.
Vehicle U398 NYO broke the speed limit by 6.53 mph.
Vehicle T626 OHU broke the speed limit by 2.14 mph.
Vehicle L247 TXV broke the speed limit by 4.53 mph.
Vehicle M362 XNK broke the speed limit by 6.77 mph.
Vehicle D953 ICB broke the speed limit by 3.83 mph.
Vehicle B766 PYQ broke the speed limit by 4.13 mph.
@tom-galvin
tom-galvin / c182e.rb
Last active August 29, 2015 14:07
DailyProgrammer Challenge #182e Solution (The Column Conundrum)
#!/usr/bin/env ruby
# /r/DailyProgrammer Challenge 182e: The Column Conundrum
words = []
columns, column_width, space_width = gets.chomp.split(' ').map {|s| s.to_i}
while (line = gets; line != nil && line.chomp.length > 0)
words += line.chomp.split(' ')
end
@tom-galvin
tom-galvin / c182e-input.txt
Created September 29, 2014 16:25
DailyProgrammer Challenge #182e Test Input
4 25 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at pharetra sapien, id sodales ipsum. Vivamus eleifend molestie tortor, vel pretium tortor venenatis nec. Nam in metus vitae nulla aliquam fringilla at vel metus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis dignissim mauris a velit facilisis ullamcorper. Ut vitae consectetur purus, eu auctor quam. Donec aliquet, urna non egestas faucibus, mauris velit vestibulum quam, eget porttitor eros dui non eros. Aliquam fringilla, mi et suscipit lacinia, libero ligula consequat quam, id facilisis neque augue eget metus. Mauris dignissim quis ex eget euismod. Nunc vitae lectus turpis. Vivamus tincidunt, est sollicitudin varius blandit, sapien quam molestie mi, eget volutpat dui mauris nec dui. Praesent tincidunt lectus ut leo tincidunt, quis consectetur sapien ultricies. Nunc erat risus, mollis in ultrices ac, posuere sit amet velit. Pellentesque semper tempus sapien id tempor. Suspendisse vitae condimentum mauris, quis imperdiet nisl.
N
@tom-galvin
tom-galvin / c182e-output.txt
Last active August 29, 2015 14:07
DailyProgrammer Challenge #182e Test Output
Lorem ipsum dolor sit felis, eleifend lacinia dictumst. Donec elementum Aliquam euismod massa vel
amet, consectetur diam facilisis egestas. risus laoreet, molestie magna consequat semper.
adipiscing elit. Ut at Nullam varius eu diam ut dui vel, volutpat dui. Sed porttitor aliquet
pharetra sapien, id iaculis. Duis viverra Aenean facilisis mollis elit, ut porttitor ipsum
sodales ipsum. Vivamus imperdiet leo quis accumsan. Nullam eu imperdiet non.
eleifend molestie tortor, condimentum. Ut tincidunt vehicula diam. Vivamus at Pellentesque tincidunt
vel pretium tortor ullamcorper velit, nec nunc eros. Proin sodales felis, sit amet
venenatis nec. Nam in sodales velit. Nulla pharetra, orci non congue pulvinar libero facilisis
metus vitae nulla aliquam porttitor mi enim, nec porta, massa metus eleifend. Donec vitae
fringilla at vel metus. blandit tellus rutrum finibus est, aliquam viverra tu
@tom-galvin
tom-galvin / c184i.cs
Created October 15, 2014 19:19
DailyProgrammer Challenge #183i Solution (Radioactive Decay)
class Program
{
static Random random = new Random();
static void Main(string[] args)
{
InputData data = GetInput();
int sampleSize = 1024;
Bitmap chart = new Bitmap(data.SimulationTime, sampleSize);