Skip to content

Instantly share code, notes, and snippets.

@dagoof
dagoof / atomic.go
Created June 3, 2022 07:54
An atomic counter written in go ...
type Counter struct {
value int32
mutex sync.Mutex
}
func (c *Counter) Increment() {
defer c.mutex.Unlock()
c.mutex.Lock()
atomic.AddInt32(&c.value, 1)
}
module Nonempty : sig
type 'a t
val init : 'a -> 'a t
val create : 'a -> 'a list -> 'a t
val head : 'a t -> 'a
val extend : 'a t -> 'a list -> 'a t
val replace: 'a t -> 'a list -> 'a t
val merge: 'a t -> 'a t -> 'a t
val of_list : 'a list -> 'a t option
val to_list : 'a t -> 'a list
module type SIG = sig
type 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
val return : 'a -> 'a t
end
module Make (M : SIG) = struct
include M
let join mm = bind mm (fun x -> x)
let map f m = bind m (fun x -> return (f x))
@dagoof
dagoof / App.js
Created January 25, 2018 05:43
5 minutes with apollo
import React, { Component } from 'react'
import { InMemoryCache } from 'apollo-cache-inmemory'
import ApolloClient from 'apollo-client'
import { ApolloProvider, graphql } from 'react-apollo'
import { HttpLink } from 'apollo-link-http'
import gql from 'graphql-tag'
const client = new ApolloClient({
ssrMode: true,
link: new HttpLink({ uri: 'https://graphql-pokemon.now.sh' }),
@dagoof
dagoof / keybase.md
Last active January 23, 2018 23:30

Keybase proof

I hereby claim:

  • I am dagoof on github.
  • I am fingernails (https://keybase.io/fingernails) on keybase.
  • I have a public key ASBBYS5_WGJMOULIpYlaC3T1lCq3JuVsVinoFw1aLBwgPQo

To claim this, I am signing this object:

@dagoof
dagoof / main.ml
Created April 12, 2016 15:15
tsdl
open Batteries
open Tsdl
exception Fucked of string
let width = 640
let height = 480
let pi = 4.0 *. atan 1.0
let value = function
@dagoof
dagoof / recovering_session.go
Last active February 7, 2018 16:27
pattern for a heartbeat that checks on a mgo session
// RecoveringSession is a session that has methods of ensuring it is still
// alive.
type RecoveringSession struct {
*mgo.Session
}
// EnsureAlive attempts to ping the session, and refreshes it if something has
// gone wrong.
func (s *RecoveringSession) EnsureAlive() {
// Squelch mgo panicing over a closed session
@dagoof
dagoof / client.go
Created September 15, 2013 12:46
echo server that tee's output
package main
import (
"flag"
"io"
"log"
"net"
"os"
)
@dagoof
dagoof / fserv.go
Created August 5, 2013 11:18
Dead simple filserver written in go as an alternative to python's simpleHTTPServer which invariably leads to frustration with it's sequential blocking access
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
var (
@dagoof
dagoof / spigot.go
Last active December 16, 2015 12:09
golang chatroom
package main
import (
"flag"
"fmt"
"io"
"log"
"net"
)