Skip to content

Instantly share code, notes, and snippets.

// Substitute this in the list of type definitions for ItemInfo
type ItemInfo struct {
NeweggItemNumber string
ItemNumber string
Title string
FinalPrice string
SpecificationGroupList []Specification
Feature map[string]string
}
@bemasher
bemasher / error.go
Created March 9, 2012 07:30
An error handling package for Golang.
package error
import (
"os"
"fmt"
"runtime"
"path/filepath"
)
// Handle an error for the calling function
@bemasher
bemasher / blink.c
Created March 5, 2012 03:05
The "Hello World" program for uC's. Blinks an LED with a 200ms period.
@bemasher
bemasher / output.txt
Created March 1, 2012 03:03
Given a list of resistor values finds a pair which provides the closest match to the given limits and typical values.
Score VLED ILED Ra Rb
0.003 3.50 0.0625 56.0 24.0
0.015 3.49 0.0685 51.0 22.0
0.021 3.48 0.0562 62.0 27.0
0.022 3.51 0.0746 47.0 20.0
0.040 3.47 0.0510 68.0 30.0
0.086 3.58 0.0526 68.0 27.0
0.094 3.59 0.0641 56.0 22.0
0.102 3.59 0.0704 51.0 20.0
0.107 3.40 0.0667 51.0 24.0
@bemasher
bemasher / error.go
Created February 20, 2012 04:01
A basic error handling package for golang.
package error
import (
"os"
"fmt"
"runtime"
"path/filepath"
)
// Handle an error for the calling function
let rec exp_refs e =
match e with
Deref (al) -> al :: []
| Neg (e1) -> exp_refs e1
| Add (e1,e2) -> (exp_refs e1) @ (exp_refs e2)
| Eq (e1,e2) -> (exp_refs e1) @ (exp_refs e2)
| _ -> []
;;
let rec active_locs c =
@bemasher
bemasher / stack.go
Last active August 19, 2020 10:59
A simple LIFO stack backed by a linked list implemented with golang.
package main
import (
"fmt"
)
type Stack struct {
top *Element
size int
}
@bemasher
bemasher / binarysearch.cpp
Created February 2, 2012 00:31
Insert and inorder walk for a Binary Search Tree.
//Binary Search Tree Program
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
class BinarySearchTree
{
private:
SELECT DISTINCT 'DELETE FROM ' + a.TABLE_NAME + ' WHERE PrimaryKeyColumn IN (SELECT PrimaryKeyColumn FROM @WhatToDelete)'
FROM INFORMATION_SCHEMA.COLUMNS a
JOIN INFORMATION_SCHEMA.TABLES b ON a.TABLE_NAME = b.TABLE_NAME
WHERE COLUMN_NAME LIKE 'PrimaryKeyColumn' AND b.TABLE_TYPE = 'BASE TABLE'
@bemasher
bemasher / solution_con.cpp
Created December 26, 2011 21:47
Single and multi-threaded solutions to Problem #23 on Project Euler in C++ with OpenMP.
#include <iostream>
#include <vector>
#include <time.h>
#include <omp.h>
using namespace std;
int SumPrimeFactors(int a) {
int s = 1;