Skip to content

Instantly share code, notes, and snippets.

Avatar
🕳️
ᕕ( ᐛ ) ᕗ

Michelle Steigerwalt Yuffster

🕳️
ᕕ( ᐛ ) ᕗ
View GitHub Profile
@Yuffster
Yuffster / Base.py
Created Dec 18, 2019
sqlalchemy base model
View Base.py
class DBModel():
def save(self):
try:
s = get_session()
s.add(self)
s.commit()
except (sa.exc.IntegrityError):
raise x.ValidationError("Invalid data.")
View sprite.css
.sprite {
background: url('./zombies.png');
--sprite-width: 32px;
--sprite-height: 48px;
--sprite-x: 0;
--sprite-y: 0;
--sheet-x: 0;
--sheet-y: 0;
--offset-x: calc((var(--sheet-x) * var(--sprite-width) * 3));
--offset-y: calc((var(--sheet-y) * var(--sprite-height) * 4));
View extensions.js
Array.prototype.smoosh = (...a) => 'arbitrary extension yay';
Array.prototype.map = (...a) => 'native overload boo';
for (let i in []) console.log(i); // only smoosh
View channels.go
package main
import "fmt"
import "time"
import "syscall"
import "os"
import "os/signal"
type fn func(os.Signal)
func catchSigterm(fun fn) {
View magic.js
class Magic {
constructor(fn, a) {
this.__chain = [[fn, a]];
}
get(t, a) {
if (a == "✨✨MAGIC✨✨") return true;
if (a == "resolve") {
return () => Magic.chain(this.__chain);
}
return (...b) => {
View basic_orm.py
import os.path
import json
import sqlite3
from contextlib import contextmanager
__data_path = None
def get_data_path(file):
return os.path.join(
os.path.dirname(__file__),
View require.js
// Global object to hold modules by their path names.
Modules = {};
Modules.__loaded__ = {};
// Give all the other scripts access to the module hierarchy.
function require(p) {
if (Modules.__loaded__[p]) {
// Only initialize each module once.
return Modules.__loaded__[p];
}
View mp3toboops.py
from pydub import AudioSegment
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
def convertAudio(f):
sound = AudioSegment.from_mp3(f)
View numbers.json
[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,5,18,23,2153,2226,2229,2231,2236,2237,2237,2238,2238,2238,2238,2239,2242,2242,2243,2243,2246,2247,2247,2248,2250,2250,2250,2264,2283,2283,2283,2283,2283,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2284,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2285,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,2286,22
View kmeans.js
function kmeans(k, arr) {
var clusters = [];
var sorted = [...new Set(arr)].sort((a, b) => a - b);
var size = Math.abs(sorted.length/k);
for (var i = 0; sorted.length>0; i += size) {
if (sorted.length < size*2) size = size*2;
clusters.push(sorted.splice(0, size));
}
console.log(clusters.map((a) => JSON.stringify(a.sort((a, b) => a - b))));
var center = (a) => {