Skip to content

Instantly share code, notes, and snippets.

Working From Earth

Ammaar Esmailjee marz619

Working From Earth
View GitHub Profile
marz619 /
Last active Dec 25, 2020
Convert a 15 character Salesforce Identier into an 18 character Identifier
# suffix characters (base 32, sort of)
def id18(s: str, *, check_suffix: bool = False) -> str:
Converts a 15 character Salesforce ID (s) to its 18 character version.
If the ID provided has length 18 and check_suffix is True, we will assert
that the suffix is correct!
marz619 /
Created May 18, 2018
Context Manager's in python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
Learning me some context managers
# NOTE: see also: contextlib.contextmanager
class Context(object):
marz619 /
Last active Jan 13, 2018
Generic URL Builder (with assumptions)
from urllib.parse import urlencode, urlparse
def build_url(base: str, *path, qparams: dict=None, trail_slash: bool=False) -> str:
As close to a generic URL builder for G-API as possible
1. base is a valid URL with an `https` scheme and a valid `netloc`
2. path is a variable number of path arguments
View buf_seq.go
package fun
// bufferedSequence
type bufferedSeq struct {
seq Seq // original Seq
buf *[]float64 // shared slice
pos int // this pos
// Next implements Seq interface
marz619 / tristate.go
Created Sep 14, 2017
Simple in memory Tristate (miss/yes/no) cache
View tristate.go
package tristate
import "sync"
// State for a tristate cache
type State int
// cache State contants
const (
Miss State = iota
marz619 /
Created Aug 27, 2017
Simple help & dir extensions for python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def dird(cls):
return a generator that yields all methods for `cls`
that do not start with underscore (_)
cn = type(cls).__name__
marz619 /
Last active Mar 26, 2020
Go build LDFlags

Using the -ldflags parameter can help set variable values at compile time.

Using the example provided here:

  1. Running make build will create a build executable. Running it will result in:
$> ./build
no version (Mon YYYY)
marz619 / stack.go
Created Jun 10, 2017
Generic Stack (golang)
View stack.go
package stack
import (
// Stack implements Push & Pop
type Stack interface {
marz619 / context_cancel.go
Last active May 25, 2017
Go (lang) context patterns
View context_cancel.go
package main
import (
marz619 / json_io.go
Last active Apr 26, 2017
simple JSON utility funcs
View json_io.go
package json
import (
// WriteJSON tries to encode `data` in to the provided io.Writer