Skip to content

Instantly share code, notes, and snippets.

@SteveBate
SteveBate / google_places_api.go
Last active October 4, 2015 17:02
Sample showing a request to Google's Places Webservice API to find addresses
package places
import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"strings"
@SteveBate
SteveBate / struct_to_bytes.go
Created October 2, 2015 14:32
Example of converting a struct to a byte slice, compressing with gzip, and saving to file followed by the reverse process back to a struct
package main
import (
"bytes"
"compress/gzip"
"encoding/gob"
"fmt"
"io/ioutil"
"log"
"os"
@SteveBate
SteveBate / linked_list_stack.go
Created September 27, 2015 08:08
A stack implemented in Go using a linkedlist data structure
package main
import (
"errors"
"fmt"
"log"
)
type ListNode struct {
number int
@SteveBate
SteveBate / sorting.go
Created September 22, 2015 10:41
Sorting in Go using the built in interface methods on a user defined type
package main
import (
"fmt"
"sort"
"time"
)
type Event struct {
Description string
@SteveBate
SteveBate / quicksort.cs
Created September 22, 2015 10:32
Quicksort algorithm implementations in Go and C#
void Main()
{
var numbers = new int[]{11, 3, 9, 15, 7, 6, 2, 1, 5, 23, 18, 4};
Quicksort(numbers, 0, numbers.Length-1);
foreach(var n in numbers){
Console.WriteLine(n);
}
}
public void Quicksort(int[] elements, int left, int right)
@SteveBate
SteveBate / zipped_webrequest.go
Last active September 20, 2015 07:30
Golang example showing how to use interfaces (Writer) to compose functionality, in this case, retrieve data from a url, encode response to a base64 string, compress it, and then save to a file. Also includes sample aspects for logging and timing
package main
import (
"bytes"
"compress/gzip"
"encoding/base64"
"fmt"
"io/ioutil"
"log"
"net/http"
@SteveBate
SteveBate / facebooktest.go
Created September 15, 2015 14:25
One possible implementation of a facebook interview question that requires the developer to take a list of users and attempt to union those records that appear to represent the same user. In the sample data, user rows 0, 2, and 3 are one user and row 1 is another therefore: Given an input of these four rows, the output should consist of only 2 rows
package main
import (
"fmt"
)
type contact struct {
name string
phone string
email string
@SteveBate
SteveBate / budget.ml
Last active August 29, 2015 14:27
A trivial sample exploring the envelope budgeting method in OCaml
open Printf
type envelope = {
name: string;
amount: int;
}
type account = {
name: string;
balance: int;
@SteveBate
SteveBate / readfile.scala
Last active August 29, 2015 14:24
quick demo of reading csv data and mapping to a value object before printing out a property on each object
import scala.io.Source
// value object - automatically implements equals and gethashcode
case class Line(lineNo: Int, partNo: String, title: String, description: String)
object Test {
// converts string array into Line value object
def toLine(args: Array[String]): Line = {
Line(args(0).toInt, args(1), args(2), args(3))
@SteveBate
SteveBate / implicitsandoptions.scala
Last active August 29, 2015 14:23
A simple example touching on Implicits and Options much like C# extensions and F# Options
object Main {
implicit class Converter(val s: String) {
def MaybeInt: Option[Int] = {
try {
Some(s.toInt)
}
catch {