Skip to content

Instantly share code, notes, and snippets.

View petejohanson's full-sized avatar

Pete Johanson petejohanson

View GitHub Profile
@petejohanson
petejohanson / PreResultComparisonInvocation.cs
Created November 10, 2010 22:14
ResultComparison<T> 'monad'
string val;
int comp = Comparer<int>.Default.Compare (0, 1);
if (comp > 0)
val = "greater than";
else if (comp < 0)
val = "less than";
else
val = "equal";
@petejohanson
petejohanson / service.rb
Created December 1, 2011 23:53
Simple Sinatra RESTful Service
require 'json'
require 'sinatra'
chief_complaints = [
{ name: "Dizziness" },
{ name: "Chest Pain" },
]
before /.*/ do
content_type :json
@petejohanson
petejohanson / riot_helper_memoize
Created January 5, 2012 12:48
Riot helpers don't memoize?
require 'teststrap'
context 'an array'do
topic { Array.new }
# Works as expected
context 'when adding an object using manual memoize' do
helper(my_object) { @my_object ||= Object.new }
hookup { topic << my_object }
@petejohanson
petejohanson / gist:1690043
Created January 27, 2012 17:59
Fun Friday Algorithm!
new[] {
new DateTime (2012, 01, 01, 13, 0, 0),
new DateTime (2012, 01, 01, 9, 0, 0),
new DateTime (2012, 01, 02, 1, 0, 0),
new DateTime (2012, 01, 02, 23, 10, 0),
}.GroupBy (dt => dt.Date)
.OrderBy (grp => grp.Key)
.SelectMany (g => g.OrderByDescending (d => d))
@petejohanson
petejohanson / gist:3513769
Created August 29, 2012 14:51
Blocking queue for connections
private BlockingQueue<Connection> pool = new LinkedBlockingQueue<Connection>(10);
private AtomicInteger connCount = new AtomicInteger();
public Connection getConnection() {
Connection conn = pool.poll(10, TimeUnit.MILLISECONDS);
if (conn == null) {
synchronized (connCount) {
if (connCount.get() < 10) {
conn = getNewConnection();
pool.offer(conn);
@petejohanson
petejohanson / gist:3938591
Created October 23, 2012 12:58
Hibernate embedded class w/ toString()
@Embeddable
public class Name {
public String getFirstName();
void setFirstName(String firstName);
public String getLastName();
void setLastName(String lastName);
@Override
public String toString() {
return firstName + " " + lastName;
@petejohanson
petejohanson / Hello.md
Created August 10, 2016 00:35
Hello EggHead-ers!

Hello!

[peter@suspect ~]$ http --print=hH get https://cryptottdemowebapi.xbtce.net:8443/api/v1/public/tick Accept:*/*
GET /api/v1/public/tick HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: cryptottdemowebapi.xbtce.net:8443
User-Agent: HTTPie/0.9.4
HTTP/1.1 200 OK
Content-Encoding: gzip
peter@suspect:~/Videos/EggHead/HTTP Fundamentals/Use HTTP POST Method $ cat ~/.local/share/gstreamer-1.0/presets/GstX264Enc.prs
[_presets_]
version=0.10
element-name=GstX264Enc
[egghead]
profile=main

Keybase proof

I hereby claim:

  • I am petejohanson on github.
  • I am petejohanson (https://keybase.io/petejohanson) on keybase.
  • I have a public key ASDOOX_E-5oRTT2YLKOoBOFNVr9kcv_a2yjxj2hy-SGd7Ao

To claim this, I am signing this object: