Skip to content

Instantly share code, notes, and snippets.

View earthboundkid's full-sized avatar

Carlana earthboundkid

View GitHub Profile
@earthboundkid
earthboundkid / tot
Last active February 28, 2020 15:12 — forked from zrzka/!IMPORTANT.md
A shell script for Tot
#!/usr/bin/env bash
# Fork of gruber's tot.sh https://gist.github.com/gruber/b18d8b53385fa612713754799ed4d0a2
# which is a fork of chockenberry's tot.sh https://gist.github.com/chockenberry/d33ef5b6e6da4a3e4aa9b07b093d3c23
#
# WARNING some options have different & potentially destructive meaning, for example:
# -r gets the dot contents in original script, but this one REPLACES the dot contents
# and does use -p to get the dot contents
#
@earthboundkid
earthboundkid / random.js
Created January 24, 2020 18:57
Generate random hex digits
function randomHex(n) {
let bytes = new Uint8Array(n);
crypto.getRandomValues(bytes);
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<template>
<div id="app">
Value is "{{ value }}". <br />
<input v-model="value" @input="handleChange($event)" />
</div>
</template>
<script>
function trimAndSpace(val) {
return val
@earthboundkid
earthboundkid / xtract.py
Created September 3, 2019 13:02
For SVG files with bloated PNG embeds
def xtract_pngs_from_svgs(name):
fname = name +'.svg'
#
with open(fname) as f:
raw = f.read()
#
prefix = 'xlink:href="data:image/png;base64,'
suffix = '"'
chunks = []
found = []
package main
import (
"fmt"
"strings"
)
func Combinations(n int, combs []int) (next func() bool) {
k := len(combs)
if k == 0 || n < k {

EDIT: On further thought, the implications of using iface.As, e.g., for io.WriterTo are quite subtle. If you were trying, say, to add logging to all Read calls, you wouldn't want to simply pass through to the underlying io.WriterTo because the call would go unlogged. Instead you'd need to implement the As method on your type so as to only return a WriterTo under certain conditions. Still, I think this idea is worth exploring more.


The Go 2 process has produced a proposal for extending the errors standard package, which is currently in testing.

My observation about the experimental errors package is: As() and Is() solve problems that exist well beyond the error interface.

Essentially the problem is this, many packages begin by requiring a certain interface, such as error, io.Reader, or

package main
import (
"bufio"
"bytes"
"fmt"
)
const html = `
<html>
@earthboundkid
earthboundkid / markov.js
Created November 5, 2018 21:16
Simple Markov text generator
class Markov {
constructor(text) {
text = text.replace(/\./g, " . ");
text = text.replace(/\s\s+/g, " ");
this.map = {};
let w1 = "";
let w2 = "";
text.split(/\s/).forEach(w3 => {
if (!this.map[w1 + " " + w2]) this.map[w1 + " " + w2] = [];
this.map[w1 + " " + w2].push(w3);