Skip to content

Instantly share code, notes, and snippets.

Avatar
🌎
Working From Earth

Ammaar Esmailjee marz619

🌎
Working From Earth
View GitHub Profile
@marz619
marz619 / id18.py
Last active Dec 25, 2020
Convert a 15 character Salesforce Identier into an 18 character Identifier
View id18.py
# suffix characters (base 32, sort of)
SUFFIX_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"
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
marz619 / ctxmngr.py
Created May 18, 2018
Context Manager's in python
View ctxmngr.py
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Learning me some context managers
"""
# NOTE: see also: contextlib.contextmanager
class Context(object):
@marz619
marz619 / url_builder.py
Last active Jan 13, 2018
Generic URL Builder (with assumptions)
View url_builder.py
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
Assumption(s):
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
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
marz619 / dir_help.py
Created Aug 27, 2017
Simple help & dir extensions for python
View dir_help.py
#!/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
marz619 / README.md
Last active Mar 26, 2020
Go build LDFlags
View README.md

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
marz619 / stack.go
Created Jun 10, 2017
Generic Stack (golang)
View stack.go
package stack
import (
"reflect"
"sync"
)
// Stack implements Push & Pop
type Stack interface {
Push(interface{})
@marz619
marz619 / context_cancel.go
Last active May 25, 2017
Go (lang) context patterns
View context_cancel.go
package main
import (
"context"
"flag"
"log"
"math/rand"
"os"
"os/signal"
"sync"
@marz619
marz619 / json_io.go
Last active Apr 26, 2017
simple JSON utility funcs
View json_io.go
package json
import (
"bytes"
"encoding/json"
"io"
)
// WriteJSON tries to encode `data` in to the provided io.Writer
//