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
@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
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 / redis_rename_keys.sh
Last active January 7, 2023 08:14
Rename Redis Keys
#!/bin/bash
# args
host=$1
shift
prefix=$1
shift
# from=$1
# shift
# to=$1
@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 / 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 / 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 / rotate_slice.go
Created December 23, 2016 21:09
Rotate a slice
package aoc
import (
"errors"
"reflect"
)
// rotate rotates the values of a slice by rotate positions, preserving the
// rotated values by wrapping them around the slice
func rotate(slice interface{}, rotate int) error {
@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 / threadpool.py
Last active February 23, 2018 12:13
A simple ThreadPool example in python
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
import time
from multiprocessing import cpu_count
from multiprocessing.pool import ThreadPool
import requests
@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