Skip to content

Instantly share code, notes, and snippets.

View chriscauley's full-sized avatar

Chris Cauley chriscauley

View GitHub Profile
@chriscauley
chriscauley / makemigrations.sh
Last active January 22, 2024 08:54
Django style migrations for alembic
#!/usr/bin/env bash
# This script gives alembic django style migrations
# Revision id is auto-incremented and autogenerate is the default behavior
# Alter this line to point to migrations folder
NEXT_ID=`ls path/to/db/versions/* | grep -P '/\d{4}_.*\.py'|wc -l`
NAME=""
FLAG="--autogenerate"
function usage() {
@chriscauley
chriscauley / nuke-space.js
Last active February 16, 2023 22:10
Nuke white space in <pre><code> tags
/*
Removes the minimum leading whitespace for each line in a pre > code tag.
Also optionally escapes html if you include the "nuke-html" class
When writing HTML snippets for slides or blogs, it's a pain to have to do this:
</div> <!-- original indentation level -->
<pre><code class="html">&lt;ul class="demo"&gt;
&lt;li&gt;No order here&lt;/li&gt;
&lt;li&gt;Or here&lt;/li&gt;
&lt;li&gt;Or here&lt;/li&gt;
class HexBoard extends React.Component {
state = {}
onMouseDown = cell => () => {
this.props.select && this.props.select(cell)
this.setState({selected: cell})
}
onMouseOver = cell => () => {
if (this.props.hover && this.state.hover !== cell) {
this.props.hover(cell)
this.setState({hover: cell})
/* solution 1 */
onSubmit(data) {
Promise.resolve(this.props.submit(data)).then(
(result) => this.setState({ result: result })
)
}
/* solution 2 */
onSubmit(data) {
const result = this.props.submit(data)
@chriscauley
chriscauley / eemacs.sh
Created October 8, 2019 14:19
Loop through files and open sequentially in emacs
# Put this in .bash_aliases or .bashrc
# USAGE:
# eemacs a.py b.py c.py
# eemacs `grep SomeClass * -rl`
# grep SomeClass * -rl | grep -v migrations | grep models.py > SOME_CLASS
# eemacs `cat SOME_CLASS`
function eemacs {
DNE=()
// css.js
export default {
button: {
default: "...", // class names
error: "..."
}
}
// MyComponent.js
body {
background: pink;
}

testing list

  • top
    • in
    • in
  • top
    • in
  • in
@chriscauley
chriscauley / gravicon.js
Created December 4, 2018 16:14
Make the favicon gray
/*
I wanted to turn my favicon gray on my development site, so I made this gist.
This is really useful for spotting which tab is which.
*/
(() => {
if (window.location.origin.indexOf("localhost") === -1) { return }
const current = document.querySelector('link[rel*="icon"]')
const img = document.createElement("img")
img.onload = () => {
const canvas = document.createElement('canvas')
.wrapped {
.occurrence { display: flex; flex-direction: row-reverse !important; min-height: 0 !important; }
.occurrence h1 { width: 80%; }
.category { display: none; }
}
@yp-conference-days-tabs-underline-color: @teal;
@yp-conference-days-tabs-tab-num-items: 3;
@yp-conference-days-content-card-hover-filter: opacity(90%);
@yp-conference-days-content-card-comedy-background-color: #94959D;
@yp-conference-days-content-card-comedy-text-color: #5C5C5E;