Skip to content

Instantly share code, notes, and snippets.

/*
I was able to achieve these speeds on my laptop: Intel Core i7-4500U @ 1.80GHZ
2015/08/19 18:48:26 Test 1: 664579 took 51.0003ms
2015/08/19 18:48:27 Test 2: 5761455 took 693.0054ms
2015/08/19 18:48:35 Test 3: 50847534 took 8.229995s
*/
package main
import (
package main
import "fmt"
type Expr interface {
Simplify() Expr
simplify() Expr
}
type const_ struct{ val int }
@ericlagergren
ericlagergren / main.go
Last active August 29, 2015 14:26
Automated Reasoning in Go
package main
import "fmt"
type Expr interface{}
type const_ struct{ val int }
type var_ struct{ name string }
type add struct{ left, right Expr }
type mult struct{ left, right Expr }
struct block{
uint8_t v[BYTES_IN_BLOCK];
block(){ memset(v, 0, BYTES_IN_BLOCK); }
uint64_t& operator[](uint8_t i){ return *(uint64_t*)(v + 8 * i); }
block& operator=(const block& r){ memcpy(v, r.v, BYTES_IN_BLOCK); return *this; }
block& operator^(const block& r){ block a; for (unsigned j = 0; j < BYTES_IN_BLOCK; ++j) a.v[j] = v[j] ^ r.v[j]; return *this; }
};
CREATE OR REPLACE FUNCTION process_password_audit() RETURNS TRIGGER AS $password_audit$
BEGIN
IF NEW.password <> OLD.password THEN
SELECT pg_notify('passwordchange', NEW);
ENDIF;
RETURN NULL;
END;
$password_audit$ LANGUAGE plpgsql;
CREATE TRIGGER password_audit AFTER UPDATE ON users
/**
* Sets the ID of the first element with the class name NAME
* to the UID that corresponds with the window's width.
*
* @param {string} name A string providing the class name of the ad element
* needing its ID changed.
* @throws {Error} If document.getElementsByClassName(name) can't find the
* element.
* @return {string} The uid.
*/
@ericlagergren
ericlagergren / map.go
Last active August 29, 2015 14:25
XML encode map golang
type CoolMap map[string]interface{}
func (c *CoolMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
var err error
for key, val := range *c {
st := xml.StartElement{
Name: xml.Name{Local: key},
}
err = e.EncodeElement(val, st)
#!/usr/bin/env bash
set -euo pipefail
// setting up stuff.
if [ "$RUN" = true ]; then
RUNSCRIPT="${BIN} ${ARGS} ${GLOGARGS} ${PROFARGS}"
echo -e "Running ${RUNSCRIPT}\n"
echo "----------------------------"
source envvar.bash # <- variable declarations are in here, and I can echo them.
eric@archbox ~/gopath/src/github.com/company/prog/testing $ cat build.bash
#!/usr/bin/env bash
set -euo pipefail
# export TEST_ENV="hello, world!"
source ev.bash
go build envtest.go && ./envtest
eric@archbox ~/gopath/src/github.com/company/prog/testing $ cat ev.bash
#!/usr/bin/env bash
set -euo pipefail
export TEST_VAR="Hello, world!"