Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / dump-cssRules.js
Created July 7, 2010 13:40
Dump all document.styleSheets[*].cssRules[*].cssText to console
// Dump all document.styleSheets[*].cssRules[*].cssText to console:
(function(s,c,r,i,j){ for(i=0;i<s.length;i++){c=s[i].cssRules;for(j=0;j<c.length;j++){r=c[j].cssText;console.log('document.styleSheets['+i+'].cssRules['+j+'].cssText = "'+r+'";')}} })(document.styleSheets);
@cowboy
cowboy / bit-string-encoding.js
Last active January 1, 2024 17:41
bit-string-encoding.js
// https://codesandbox.io/s/bit-string-compression-zydb3?file=/src/App.js
const name = 'test_example'
const width = 48
const height = 48
const arr = [
0xffffff000000,
0x8000017ffffe,
0xbffffd400002,
0xa00005400002,
@cowboy
cowboy / quine-examples.js
Last active December 23, 2023 08:51
A few JavaScript quines
// Today, I noticed that someone favorited this tweet of mine from 2012:
// https://twitter.com/cowboy/status/232587756486938624
// !function $(){console.log('!'+$+'()')}() #quine
// So I fooled around for a little bit:
// Shortest JavaScript quine?
(function _(){return'('+_+')()'})()
// Have fun with this one!
@cowboy
cowboy / cowboy-midi-sustain-filter.c
Last active December 22, 2023 21:51
USB MIDI "proxy" that converts Note On + Sustain + Note Off => Note On + "Sustained" Note Off for devices that don't handle Sustain (CC 64) well
// To give your project a unique name, this code must be
// placed into a .c file (its own tab). It can not be in
// a .cpp file or your main sketch (the .ino file).
#include "usb_names.h"
// Edit these lines to create your own name. The length must
// match the number of characters in your custom name.
#define MIDI_NAME {'C', 'o', 'w', 'b', 'o', 'y', ' ', 'F', 'i', 'l', 't', 'e', 'r'}
@cowboy
cowboy / usb-din-midi-device.c
Last active December 11, 2023 08:44
USB MIDI device -> filter -> DIN MIDI out - for Teensy LC
// To give your project a unique name, this code must be
// placed into a .c file (its own tab). It can not be in
// a .cpp file or your main sketch (the .ino file).
#include "usb_names.h"
// Edit these lines to create your own name. The length must
// match the number of characters in your custom name.
#define MIDI_NAME {'R','e','n','a','m','e',' ','M','e',' ','D','u','d','e'}
@cowboy
cowboy / #bf4-emblem-import-export.md
Last active December 3, 2023 17:43
JavaScript: BF4 Battlelog Emblem Import / Export

Exporting an emblem

  1. Log into BF4 Battlelog.
  2. Visit the Customize emblem page.
  3. Select the emblem you wish to export.
  4. Open the console (Ctrl-Shift-J).
  5. Enter the following code snippet to copy the raw emblem data to the clipboard:
    copy('emblem.emblem.load('+JSON.stringify(emblem.emblem.data,null,2)+');');
  6. Paste somewhere useful, like a gist. Whatever.
  7. Close the console (Ctrl-Shift-J).
@cowboy
cowboy / .gitignore
Created September 30, 2020 17:57
kicad gitignore
# Adapted from:
# https://github.com/github/gitignore/blob/master/KiCad.gitignore
# For PCBs designed using KiCad: http://www.kicad-pcb.org/
# Format documentation: http://kicad-pcb.org/help/file-formats/
# Temporary files
*.000
*.bak
*.bck
@cowboy
cowboy / ocd.log
Created September 10, 2012 13:34
bot-t: hi5
[09:09] <@rmill> o/\o
[09:09] <@rmill> common abbreviation for "boo-yah"
[09:10] <@rmill> _o/\o_
[09:10] <@ben_alman> ?hi5 rmill
[09:10] <bot-t> ben_alman, Couldn't find "hi5 rmill" in jQuery Docs.
[09:10] <@ben_alman> FINE
[09:10] <@rmill> :'(
[09:10] <@ben_alman> ?eval hi5(" rmill ben_alman ")
[09:10] <bot-t> ben_alman: " rmill ben_alman "
[09:10] <@ben_alman> o well
@cowboy
cowboy / abstraction-2020.js
Last active September 24, 2023 12:24
Abstraction.js 2020 Edition (ES6)
/*
* Abstraction.js 2020 Edition
*
* Copyright (c) 2020 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
let $elseif, $else, $if = state => state ? (
$elseif = () => () => {},
@cowboy
cowboy / cowboy-akai-force-rec-pedal-matrix.ino
Last active September 20, 2023 05:43
Akai Force Rec Pedal w/ 8x8 Matrix Display (USB MIDI) - for Teensy LC
// ===============================================================
// Akai Force Rec Pedal w/ 8x8 Matrix Display (USB MIDI) - for Teensy LC
// "Cowboy" Ben Alman, 2021
// https://gist.github.com/cowboy/6c2230d54aea58577c5b7953ea86aebe
// ===============================================================
// Why does this exist?
//
// I designed this to circumvent an issue with the Akai Force where receiving
// an MMC Rec message signals that the loop should end at the end of the