Skip to content

Instantly share code, notes, and snippets.

@gknoy
gknoy / iterm2-badge.sh
Created November 3, 2017 22:48
iterm2 terminal helpers (sourced as part of login)
#! /bin/bash
#
# iterm2-badge.sh
#
# Send escape sequences so that iterm2 can set the badge to arbitrary text
#
# https://www.iterm2.com/documentation-badges.html
#
function iterm2_print_user_vars() {
@gknoy
gknoy / 2x3.py
Created September 5, 2017 17:58
2x3.py
"""
A 2x3 rectangle is divided into 6 squares A, B, C, D, E, and F.
I represent the painted 2x3 array as a list of six items, for easier indexing
+---+---+---+
| A | B | C |
+---+---+---+ => [A, B, C, D, E, F]
| D | E | F |
+---+---+---+
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
divs: Array.from(Array(100).keys())
});
@gknoy
gknoy / controllers.application.js
Last active September 1, 2016 21:47
default value propagation
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
remodal: Ember.inject.service(),
name: 'Name',
actions: {
rename (name) {
this.set('name', name)
@gknoy
gknoy / demo_attrs.py
Created August 25, 2016 21:19
Demo renaming `attr` library helpers to less-clever names
#
# demo_attrs
#
import attr
@attr.s
class Foo(object):
x = attr.ib()
# paste directly into console
In [2]: class Sample:
...:
...: def __init__(self):
...: print('hehe')
...:
In [3]: s = Sample()
hehe
@gknoy
gknoy / flip
Created February 26, 2016 00:09
flip text
#! /bin/sh
#
# alias flip='echo "(╯°□°)╯︵ ┻━┻"'
#
# requires `pip install upsidedown`
#
prefix='(╯°□°)╯︵'
flipped='┻━┻'
@gknoy
gknoy / gh-wider.js
Last active August 29, 2015 14:26
gh-wider: Relax the width constraints in Github's Pull Requests' "Files Changed" view (Chrome)
// Saved as a bookmark:
// (which apparently only works in Chrome)
javascript:(function (){ var newcss = ".container { width: 100%; } .repository-with-sidebar .repository-content { width: -moz-calc(100% - 90px); width: -webkit-calc(100% - 90px); width: calc(100% - 90px); }"; if ("\v" == "v") { document.createStyleSheet().cssText = newcss } else { var tag = document.createElement("style"); tag.type = "text/css"; document.getElementsByTagName("head")[0].appendChild(tag); tag[(typeof document.body.style.WebkitAppearance == "string") ? "innerText" : "innerHTML"] = newcss; }})();
// beautified with js-beautify:
javascript: (function() {
var newcss = ".container { width: 100%; } .repository-with-sidebar .repository-content { width: -moz-calc(100% - 90px); width: -webkit-calc(100% - 90px); width: calc(100% - 90px); }";
if ("\v" == "v") {
document.createStyleSheet().cssText = newcss
} else {
@gknoy
gknoy / spaces-to-tabs
Created March 25, 2015 16:56
spaces-to-tabs: Simple regex sample
#! /usr/bin/perl
#
# spaces-to-tabs-filter
#
# A simple regex example
# perl -e 'while (<>) { $line = $_; $line =~ s/ /\t/g; print $line; }' < foo_spaces.py > foo_tabs.py
#
while (<>) {