Skip to content

Instantly share code, notes, and snippets.

View craigcalef's full-sized avatar
💭
It is by my will alone that I set my mind in motion.

Craig Calef craigcalef

💭
It is by my will alone that I set my mind in motion.
View GitHub Profile
@craigcalef
craigcalef / watertrap.r
Created January 18, 2023 07:12
If you have rain that falls on a graph how do you figure out which valleys have trapped water with probably the most in-elegant algorithm possible
fn main() {
let height: [i8; 12] = [0,1,0,2,1,0,1,3,2,1,2,1];
let len = height.len();
let mut left_highest: i8;
let mut right_highest: i8;
let mut sum_ground: i8 = 0;
let mut sum_gwater: i8 = 0;
let mut gwater_here: i8;
let mut left_i: usize;
let mut right_i: usize;
>>> def spengbob(s):
... return "".join([c.lower() if i % 2 == 0 else c.upper() for i, c in enumerate(s)])
...
>>> spengbob("massachusetts")
'mAsSaChUsEtTs'
#!/bin/bash
# Shame people using too much disk. Good for your /etc/update-motd.d
# Lol what is this the 90s?
PCENT=$(df --output=pcent /home | tr -dc '0-9')
if (( $PCENT > 90 )); then
echo -e "\033[5mDisk usage has exceeded 90%\033[0m"
df -h /home
fi
@craigcalef
craigcalef / daychange.py
Created April 18, 2019 23:06
Calculate length of day change over the year
import ephem
import datetime
# ephem.localtime(ephem.next_summer_solstice('2019-1-1'))
s = ephem.Sun()
o = ephem.city('Boston')
yesterday_len = 0
for i in range(0, 365):
d = datetime.datetime(2019,1,1,16,0) + datetime.timedelta(i)
import csv
import pprint
with open('salesdata.csv', 'r') as f:
cars = [{k: v for k, v in row.items()} for row in csv.DictReader(f, skipinitialspace=True)]
fords = filter(lambda x: x['Make'] == 'FORD', cars)
v8 = filter(lambda x: '5.8' in x['Engine'], fords)
zips = open('zips.txt', 'r').read().strip().split(',')
local = filter(lambda x: x['Location ZIP'] in zips, v8)
if local:
pprint.pprint(local)
@craigcalef
craigcalef / gist:4d96b7d11cb1a5d7a1a920517d04c1e6
Created December 23, 2017 05:23
Send host/service notifications from Nagios via AWS SES
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line aws ses send-email --from [email protected] --to $CONTACTEMAIL$ --text "***** dev1 Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Host: $HOSTNAME$ State: $HOSTSTATE$ Address: $HOSTADDRESS$ Info: $HOSTOUTPUT$ Date/Time: $LONGDATETIME$" --subject "dev1 $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$" --region us-west-2
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line aws ses send-email --from [email protected] --to $CONTACTEMAIL$ --text "***** dev1 Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ Host: $HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ Additional Info: $SERVICEOUTPUT$" --subject "dev1 $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" --region us-west-2
@craigcalef
craigcalef / pq.py
Created October 4, 2017 19:47
pq. its like jq, you know, but for python.
#!/usr/bin/env python
"""
pq. its like jq, you know, but for python.
caution: super hackey.
"""
import json
import sys
import atexit
@craigcalef
craigcalef / gist:9171365
Created February 23, 2014 13:20
an ode to the perfect input device
Why must you tempt me with that image. You can't buy the Trackman Marble FX any more. Not for atleast 8 years. It fetches a handsome price on eBay as well. This was the apex of trackball input devices. What I wouldn't give to have one of these today. The Trackman Marble I use now is very nice but its not as perfectly sculpted as the FX. Maybe 3d printing can bring this masterpiece back to us.
In other "i am super persnickety about my input peripherals" news: the new elongated nubbules on the bottom of the Dual Shock 4 controller dig into my palms and cause crazy amounts of fatigue-- something I never experienced with the same button layout but with a Dual Shock 3 controller with much smaller protuberances.
@craigcalef
craigcalef / slipstream
Last active January 1, 2016 21:08
Ubuntu preseed for fast, automated installation.
# Ubuntu Server Quick Install
# Based on http://bit.ly/uquick-doc by Dustin Kirkland <[email protected]>
# Boot via DHCP, seriously wipe the disk DO IT
# Add boot options: priority=critical locale=en_US url=https://gist.github.com/craigcalef/8201088/raw
#
d-i debian-installer/locale string en_US.UTF-8
d-i debian-installer/splash boolean false
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
@craigcalef
craigcalef / gist:7983832
Created December 16, 2013 08:23
The Obituary Guest Book of John W. Eklund
November 19, 2013
My deepest sympathies to you and yours. Sending all of my love and strength.
~ Kelly Smith Kilmer, Los Angeles, California
Contact Me
November 19, 2013
Jenn and Brian we are so sorry for you loss. May all your memories comfort you. We love you and are here if you need us
~ Deb Rob and Liam Ahern, Pascoag, Rhode Island
November 18, 2013
RIP uncle John! I'm so sorry I didn't see you first. Thanks for always being so good to us kids. Love you forever!
~ Cameron Calef, Quincy, Massachusetts