Skip to content

Instantly share code, notes, and snippets.

View macabreb0b's full-sized avatar

a knee macabreb0b

View GitHub Profile
@macabreb0b
macabreb0b / Code.gs
Last active January 17, 2024 10:12
email eater - google apps script (with dynamic label support)
// script forked from https://gist.github.com/jamesramsay/9298cf3f4ac584a3dc05
// to start timed execution: select "Install" from the menu above and hit "run"
// to stop timed execution: select "Uninstall" from the menu above and hit "run"
// to initialize a batch run ad-hoc and immediately: select "_processNextBatch" from the menu above and hit "run"
// runbook:
// - namespace labels like ee-
// - name labels like ee-archive-after-8d, ee-delete-after-45d
// - you can give a message more than one label (e.g., ee-archive-after-1d, ee-delete-after-5d)
@macabreb0b
macabreb0b / Code.gs
Last active January 17, 2024 00:40
email eater - google apps script
// script forked from https://gist.github.com/jamesramsay/9298cf3f4ac584a3dc05
// to start timed execution: select "Install" from the menu above and hit "run"
// to stop timed execution: select "Uninstall" from the menu above and hit "run"
// to initialize a batch run ad-hoc and immediately: select "_processNextBatch" from the menu above and hit "run"
const LABELS_TO_DELETE = [
// ... list of labels ...
// 'test-delete-after-label',
'spammy-alerts',
// 'delete-after-30d',
@macabreb0b
macabreb0b / autodelete_bot.py
Last active December 14, 2023 20:34
discord autodelete bot script
# sourced from https://pastebin.com/12UpbQHT
import discord
from discord.ext import tasks, commands
from datetime import datetime, timedelta
bot_token = "some-bot-token"
# replace with your channel ID
channel_id = 1111
bot_prefix = "!"
@macabreb0b
macabreb0b / button_click_trumps_form_submit.html
Created May 30, 2018 22:46
calling preventDefault on button.click event stops form.submit from triggering
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>preventDefault on button.click stops form.submit from triggering</title>
<style>
</style>
</head>
<body>
<form>
@macabreb0b
macabreb0b / html5-blank-template
Last active October 16, 2018 18:17 — forked from iwek/html5-blank-template
HTML5 Blank Template with jQuery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Blank HTML5</title>
<style>
</style>
</head>
<body>
@macabreb0b
macabreb0b / pytest_best_practices.md
Last active January 31, 2018 02:45
Some pytest notes

mocking

mock.Mock() is great. It's the reason that I use Python for small side projects - it makes unit testing a breeze. But over-reliance on mock objects for testing can obscure the meaning of your test (at best), and (at worst) it can create bugs in your test code.

  1. Use spec_set when creating object fakes.
  2. Use autospec=True when stubbing method functionality.

fixtures

Similar to mock.Mock(), Pytest fixtures (functions defined with the decorator @pytest.fixture()) can be super handy for writing unit tests, but if they are overused, they can obscure the meaning of what you're testing.

Some issues with fixtures:

@macabreb0b
macabreb0b / js_class_notation.js
Created December 5, 2017 07:47
Movie Title Typeahead in JS
class MovieTypeaheadNode {
constructor(parent, value) {
this.value = value;
this.parent = parent;
this.children = [];
this.matchingMovies = [];
}
addChild(letter) {
let child = this.childWithValue(letter);
@macabreb0b
macabreb0b / PhotoInput.jsx
Last active October 19, 2017 08:06
handle photo upload with React
import React, { Component } from 'react';
class PhotoInput extends Component {
constructor(props) {
super(props)
this.state = {
fileData: '',
}
@macabreb0b
macabreb0b / method_naming.md
Last active July 8, 2022 00:47
A method-naming flow chart

because there's so much more than "get"

Is your method retrieving a record(s) from a data source? (e.g., a database or external service, or making a GET request)

get_*
fetch_*

Is your method creating a new record in a data source?

@macabreb0b
macabreb0b / some_thoughts_on_testing.md
Last active March 20, 2018 21:43
Some thoughts on testing
  • Tests should be "stupid"
    • Don't include complex logic
  • Tests should be easy to understand
    • Give your tests descriptive names
    • Ask "will the person who sees this test fail understand why it's failing?"
  • Tests should not be DRY
  • Easy-to-test code is good code / Hard-to-test code is bad code
    • your tests should instruct your feature code
~good test~