Skip to content

Instantly share code, notes, and snippets.

View dhconnelly's full-sized avatar

Daniel Connelly dhconnelly

View GitHub Profile
@dhconnelly
dhconnelly / vm.ml
Last active February 29, 2020 16:07
Advent of Code 2019 Intcode VM in OCaml
module IntMap = Map.Make(Int)
type data = int IntMap.t
let empty = IntMap.empty
let set x pos data = IntMap.add pos x data
let get pos data = match IntMap.find_opt pos data with
| None -> 0
| Some x -> x
let read ic =
let next_instr () = try Some (Scanf.bscanf ic "%d%c" (fun i _ -> i))

Data structures in Go with maps and slices

Sets:

set := make(map[string]bool)

// add to set
set["a"] = true 

rust

https://www.rust-lang.org/

features

  • traits (interfaces), enums (abstract data types), generics
  • pattern matching and destructuring
  • memory safety, no nulls, smart pointers, borrow-checking, raii

Keybase proof

I hereby claim:

  • I am dhconnelly on github.
  • I am dhconnelly (https://keybase.io/dhconnelly) on keybase.
  • I have a public key whose fingerprint is D398 9646 0911 1113 522F BE63 E048 B342 DE7D BB12

To claim this, I am signing this object:

@dhconnelly
dhconnelly / chromium-start.sh
Last active December 26, 2015 08:19
chromium development setup
#!/bin/bash -e
# depot_tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
echo "export PATH=$PWD/depot_tools:$PATH" >> $HOME/.bashrc
source ~/.bashrc
# get chromium
mkdir chromium
cd chromium
@dhconnelly
dhconnelly / tufind.py
Created October 23, 2013 14:12
find a string in a file's include set
#!/usr/bin/env python2.7
import itertools
import sys
def contains(filename, string):
'''Determine whether a file contains a string.'''
with open(filename) as f:
for num, line in zip(itertools.count(1), f.readlines()):
if string in line:
@dhconnelly
dhconnelly / for.py
Created March 29, 2012 12:52
for loops tutorial for GSMST number theory
# what if we have a list, and we want to do something for each item.
nums = [12, 5, 7, 18, 127, -1337]
# we will print out each number squared
# this means: repeatedly take one element from the list "nums"
# call it "num"
# and do the stuff in the for loop body.
for num in nums:
print num * num
@dhconnelly
dhconnelly / dictionaries.py
Created March 29, 2012 12:45
dictionaries tutorial for GSMST number theory
# let's say we want to keep track of a person.
# me.
daniel = {
'fname': 'Daniel',
'lname': 'Connelly',
'age': 25,
'city': 'Atlanta'
@dhconnelly
dhconnelly / lists.py
Created March 29, 2012 12:30
lists tutorial for GSMST number theory
# sometimes we want to keep track of lots of things, without naming
# each one individually
# we want to read some names from the user
# what if we want to hold onto all of the names and do something with
# them later?
# for instance, we want to print them in reverse
@dhconnelly
dhconnelly / functions.py
Created March 29, 2012 12:05
brief tutorial on functions for GSMST number theory
# -----------------------------------------------------------------------------
# A brief tutorial on functions
# by Daniel Connelly (dhconnelly@gmail.com)
# -----------------------------------------------------------------------------
# Sometimes we want to re-use a piece of programming logic. Copy-and-paste is
# not necessarily a good approach, as it is prone to errors and duplicates
# work. A good maxim is "Don't Repeat Yourself." Let's see how we can use
# functions to eliminate repetition.