Skip to content

Instantly share code, notes, and snippets.

@scwood
scwood / retry.py
Last active September 24, 2019 19:38
Retry decorator in Python
import random
import time
# This is the decorator - it's essentially a function that takes in a function
# as a parameter and returns a modified version of it
def retry(func, max_attempts=4, initial_delay=1):
def wrapper(*args, **kwargs):
delay = initial_delay
attempt = 1
while True:
@scwood
scwood / expansion.py
Last active September 13, 2019 18:46
Variable expansion
# Another idea, you could avoid any "custom language" / parsing / regex stuff by just referencing
# variables by ID an having them provide valid python strings that have format placeholders
# documentation on the string.format function: https://www.geeksforgeeks.org/python-format-function/
json = {
'variables': {
'foo': 'asdf',
'bar': 'fdsa'
},
@scwood
scwood / scp2.bash
Created January 31, 2019 22:13
scp example pt. 2
$ ssh b1
Last login: Thu Jan 31 15:08:19 2019 from 10.82.35.207
[ops.b1-prv][swood@rampart1-app ~]$ mkdir -p foo/bar/codebase
[ops.b1-prv][swood@rampart1-app ~]$ touch foo/bar/codebase/a.c
[ops.b1-prv][swood@rampart1-app ~]$ touch foo/bar/codebase/b.c
[ops.b1-prv][swood@rampart1-app ~]$ cd foo/bar/codebase/
[ops.b1-prv][swood@rampart1-app codebase]$ pwd
/mnt/home/swood/foo/bar/codebase
[ops.b1-prv][swood@rampart1-app codebase]$ logout
Shared connection to rampart.b1-prv.qops.net closed.
@scwood
scwood / scp.bash
Created January 31, 2019 22:05
scp example
$ ssh b1
Last login: Thu Jan 31 15:02:56 2019 from 10.82.35.207
[ops.b1-prv][swood@rampart1-app ~]$ touch test.txt
[ops.b1-prv][swood@rampart1-app ~]$ logout
Shared connection to rampart.b1-prv.qops.net closed.
~/workspace
$ scp b1:test.txt .
test.txt 100% 100% 0 0.0KB/s 00:00
$ ls
test.txt
@scwood
scwood / promise.all.js
Last active November 29, 2018 23:14
Promise.all implementation
function all(promises) {
return new Promise((resolve, reject) => {
if (!isIterable(promises)) {
reject(new TypeError(`${promises} is not iterable`))
return
}
const promisesArray = [...promises]
if (promisesArray.length === 0) {
resolve([])
return
@scwood
scwood / wow.md
Last active September 26, 2018 18:46
My WoW addons + resources

Useful links

  • RaidBots - Allows you to sim your character to find the best gear combinations, generate stat weights, etc. (requires Simulationcraft addon)
  • Warcraft Logs - Combat analysis for raid encounters. Gives your percentile ranking relative to the other players of your class and iLvL around the world. Someone in the guild might already be recording these but if not (or if you just want to upload them yourself) the getting started guide is helpful.
  • WoWAnalyzer - If you or the guild is recording logs you can plug a WL report into this app and get an analysis of where you're screwing up. Example.
  • Twitch Desktop App - Best tool for installing / updating your addons. After installing go to Mods -> World of Warcraft.
  • [Icy Veins](https://www.icy-ve
@scwood
scwood / chunkingpromises.js
Last active September 11, 2018 22:23
chunking promise.all and capturing all the promises
const chunkAsync = (arr, callback, chunkSize = 1) => {
const results = []
const chunks = chunkArray(arr, chunkSize)
const work = chunks.reduce((previousPromise, chunk) => {
return previousPromise.finally(() => {
results.push(...chunk.map(callback))
return Promise.all(results)
})
}, Promise.resolve())
return work.finally(() => results)
// Anything wrong with doing this?
class ExampleComponent extends Component {
defaultState = {
isLoading: false,
fileUploaded: false,
currentFile: null,
pendingImports: null,
}
@scwood
scwood / mergeTwoSortedLists.js
Created July 25, 2018 16:26
Merging two sorted lists
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} l1
* @param {ListNode} l2
@scwood
scwood / bootstrap_custom.css
Created July 22, 2018 06:02
bootstrap_custom.css
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2016 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
.bs fieldset {
padding: 0;
margin: 0;
border: 0;
min-width: 0; }