Skip to content

Instantly share code, notes, and snippets.

View ideasasylum's full-sized avatar

Jamie Lawrence ideasasylum

View GitHub Profile
@ideasasylum
ideasasylum / counter.py
Last active May 16, 2023 12:50
Badger examples
# A very simple Badger script which displays a counter and allows you to increment/decrement it with the up/down buttons
import badger2040
badger = badger2040.Badger2040()
display = badger.display
display.set_update_speed(badger2040.UPDATE_FAST)
number = 0
def clear():
@ideasasylum
ideasasylum / 1.txt
Created May 14, 2022 09:53
This is a script to present "slides" (text files) on a [Badger 2040](https://shop.pimoroni.com/products/badger-2040?variant=39752959852627)
image
images/podia-logo.bin
@ideasasylum
ideasasylum / character_frequency.rb
Created January 17, 2022 21:14
Counts the frequency of characters in an AR collection
class CharacterFrequency
include Enumerable
# Take an AR collection and a block to extract the attribute value
def initialize collection, &block
@collection = collection
@block = block
end
def print
@ideasasylum
ideasasylum / active_record_dependancy_graph.rb
Last active February 27, 2021 23:13
Check if an ActiveRecord model can be destroyed, and in what order the association should be deleted
Rails.application.eager_load!
class ActiveRecordDependancyGraph
include TSort
attr_reader :graph
def initialize root_model
@graph = {}
@model = root_model
fetch_children @model
@ideasasylum
ideasasylum / upgrade.rake
Created March 21, 2018 14:23
Stupid rake task to randomly pick one outdated gem
require 'open3'
require 'rainbow'
desc "Upgrade gems"
namespace :upgrade do
desc "Find a random gem to update"
task :bingo => :environment do
cmd = 'bundle outdated'
stdout, stderr, status = Open3.capture3(cmd)
@ideasasylum
ideasasylum / keybase.md
Created August 17, 2016 10:09
keybase.md

Keybase proof

I hereby claim:

  • I am ideasasylum on github.
  • I am ideasasylum (https://keybase.io/ideasasylum) on keybase.
  • I have a public key whose fingerprint is ED31 FE9E E32F 0D88 27FB CB25 A4DF 38FA A95D 637D

To claim this, I am signing this object:

@ideasasylum
ideasasylum / previously_dirty.rb
Created May 10, 2016 14:49
Dirty state tracking for previous changes
module PreviouslyDirty
extend ActiveSupport::Concern
include ActiveModel::AttributeMethods
included do
attribute_method_suffix '_previously_changed?', '_previously_was'
end
# Handle <tt>*_previously_changed?</tt> for +method_missing+.
def attribute_previously_changed?(attr, options = {}) #:nodoc:
@ideasasylum
ideasasylum / translate_aws.js
Created May 6, 2016 10:22
A Chrome UserScript to replace AWS names with sensible stuff
// ==UserScript==
// @name Translate Amazon
// @namespace http://ideasasylum.com
// @version 0.1
// @description Translate the Amazon service names into plain English. See https://www.expeditedssl.com/aws-in-plain-english
// @author @ideasasylum
// @match https://*.console.aws.amazon.com/console/home?*
// @grant none
// ==/UserScript==
@ideasasylum
ideasasylum / navbar.html
Created January 15, 2016 23:41
Navbar in hugo
<div class="top-bar">
<div class="top-bar-left">
<ul class="menu align-right">
<li class='menu-text'><a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a></li>
</ul>
</div>
<div class="top-bar-right">
<ul class="menu">
{{ $currentNode := . }}
@ideasasylum
ideasasylum / wercker.yml
Created January 15, 2016 23:33
wercker.yml file for a Hugo site with s3 deployment
box: debian
build:
steps:
- arjen/hugo-build:
version: "0.15"
theme: "rw-theme"
deploy:
steps: