Skip to content

Instantly share code, notes, and snippets.

View abachman's full-sized avatar
🙌
good times

Adam Bachman abachman

🙌
good times
View GitHub Profile
@abachman
abachman / db-joins.md
Last active November 3, 2022 14:59
DB Joins in MySQL

Given a database with two tables.

select * from users;
+----+------+
| id | name |
+----+------+
@abachman
abachman / jest.d.ts
Last active July 21, 2022 16:22
attempt at an all-in-one jest performance expectation
declare global {
namespace jest {
interface Matchers<R> {
toBeFasterThan(target: number): Promise<CustomMatcherResult>;
}
}
}
@abachman
abachman / 0. why
Created April 16, 2011 18:28
acclimating myself to the Mac keyboard layout by reclaiming keyboard shortcuts. https://twitter.com/#!/abachman/status/59323764772569088
For the last two years I've been using Ubuntu Linux for software development.
Last week I got a MacBook Pro and have been changing over. I run a heavily
customized vim setup, so the change was particularly difficult with regards to
my keyboard layout.
These step show what I did to make my Mac work like my Linux machines which all
have caps-lock remapped to control. I used OSX's built in keyboard setup tool
to remap my caps-lock key to be a command key, since command, for the most
part, takes the place of control as the primary shortcut key modifier.
@abachman
abachman / conditional_chaining_with_tap.rb
Created October 12, 2010 04:01
Conditional query chaining in Rails 3
# I want a list of 6 non-administrators who are not the
# current user only if someone is logged in. Otherwise,
# don't check current_user's id.
# instead of this:
if user_signed_in?
@other_users = User.non_admin.limit(6).where("name IS NOT NULL")
else
@other_users = User.non_admin.limit(6).where(['id != ?', @user.id]).where("name IS NOT NULL")
// Adafruit IO Digital Input Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-digital-input
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016 Adafruit Industries
// Licensed under the MIT license.
@abachman
abachman / passphrase-generator
Created September 7, 2021 13:32
passphrase generator
#!/usr/bin/env ruby
# ws=open('/usr/share/dict/words').readlines.map(&:strip).select{|w|/^[a-z]{7}$/=~w};100.times{p ws.sample(6).join(' ')}
ws=open('/usr/share/dict/words').readlines.select {|w|
/^[a-z]{5,7}\b/ =~ w
}.map(&:strip)
def n
(rand() * 89 + 10).floor.to_s
end
@abachman
abachman / download_paged_data.py
Last active July 9, 2021 15:25
Download data in bulk from Adafruit IO
#!/usr/bin/env python
"""
Download all data from a list of Adafruit IO feeds. Change constants in this
file in the CONFIGURATION section before you run the script.
Usage:
$ START="2019-05-01T00:00Z" END="2019-06-01T00:00Z" \
python download_paged_data.py
"""
@abachman
abachman / Adafruit Naming Examples.md
Last active March 28, 2021 17:05
Adafruit Naming Examples

To run these examples, you'll need the Ruby MQTT library:

$ gem install mqtt

And you'll need to set the various environment variables the scripts expect to find. To do that, create a file named profile in the same directory you plan to run the scripts from. Fill in the AIO_USER and AIO_KEY values with your own.

$ cat &lt; profile
@abachman
abachman / index.js
Created January 25, 2021 02:35
Signaling Server
// npm install; npm start
const http = require('http'),
faye = require('faye');
const server = http.createServer(),
bayeux = new faye.NodeAdapter({mount: '/signal', timeout: 45});
bayeux.attach(server);
server.listen(8080);
@abachman
abachman / esp8266-Adafruit_MQTT-get-test.ino
Created June 5, 2018 17:34
Demo of the {topic}/get MQTT topic with the Adafruit_MQTT library
/***************************************************
Adafruit MQTT Library ESP8266 Example
Must use ESP8266 Arduino from:
https://github.com/esp8266/Arduino
Works great with Adafruit's Huzzah ESP board & Feather
----> https://www.adafruit.com/product/2471
----> https://www.adafruit.com/products/2821