Skip to content

Instantly share code, notes, and snippets.

View marz619's full-sized avatar
🌎
Working From Earth

Ammaar Esmailjee marz619

🌎
Working From Earth
View GitHub Profile
set nocompatible " Use Vim defaults (much better!)
set bs=2 " allow backspacing over everything in insert mode
set ai " always set autoindenting on
set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
" 000328 from article in Linux Journal, Apr 2000
set incsearch " searches as you enter the string!
set ignorecase " Ignore case in searching for matches set smartcase " Ignore case ONLY if all lower case srch str
@marz619
marz619 / id18.py
Last active November 18, 2022 13:48
Convert a 15 character Salesforce Identier into an 18 character Identifier
# 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 15:59
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
marz619 / url_builder.py
Last active January 13, 2018 23:29
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
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
@marz619
marz619 / buf_seq.go
Last active April 15, 2024 17:55
Composition & Higher-Order Functions in Golang (via: https://faiface.github.io/post/how-i-built-audio-lib-composite-pattern/)
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 September 14, 2017 17:12
Simple in memory Tristate (miss/yes/no) cache
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 August 27, 2017 20:33
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
marz619 / README.md
Last active March 26, 2020 17:41
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
marz619 / stack.go
Last active October 30, 2022 07:20
"Generic" Stack (Go-lang <pre-generics>)
package stack
import (
"reflect"
"sync"
)
// Stack implements Push & Pop
type Stack interface {
Push(interface{})
@marz619
marz619 / context_cancel.go
Last active May 25, 2017 05:02
Go (lang) context patterns
package main
import (
"context"
"flag"
"log"
"math/rand"
"os"
"os/signal"
"sync"