Skip to content

Instantly share code, notes, and snippets.

{ config, pkgs, ... }:
let
chatServer = "chat.example.com";
in
{
imports = [
./hardware-configuration.nix
];
@jpf
jpf / clean-token.el
Created August 26, 2019 05:09
Clean up passwords and tokens for use in documentation
;; Turns a password like "qWXNNXb6m(TM77WiVtC87c*" into "aABCDEb0c(FG12HdIeJ34f*"
;;
;; Use the clean-token function by marking a region you want to be "cleaned" and then running M-x clean-token
(defun token-cleaner (token)
"Given a TOKEN as a string, return a string where the letters in TOKEN have been replaced with letters from the same type"
(defun next-letter (letter smallest-letter largest-letter)
"Given LETTER, return the next letter in the sequence between SMALLEST-LETTER and LARGEST-LETTER"
(let ((proposed-letter (char-to-string (1+ (string-to-char letter)))))
(if (string> proposed-letter largest-letter)
smallest-letter
@jpf
jpf / count-bits.py
Created August 27, 2018 20:17
Counts the number of "1" and "0" bits in an input file
#!/usr/bin/env python3
# Counts the number of "1" and "0" bits in an input file
import sys
bits_per_byte = 8
# Via: https://stackoverflow.com/a/1035456
def bytes_from_file(filename, chunksize=8192):
with open(filename, "rb") as f:
while True:
var tracery = require('tracery-grammar'); // https://github.com/v21/tracery
var grammar = tracery.createGrammar({
'aas': ['#thing# as a service.'],
'thing': [
'Chaos',
'Denial of Service',
'Insurrection',
'Monday',
'Sucks',
'apocalypse',
@jpf
jpf / nix_and_python.py
Created June 1, 2016 18:00
A Python script that uses Nix to automatically bootstrap dependencies.
#! /usr/bin/env nix-shell
#! nix-shell -i python -p python27Packages.flask python27Packages.emoji
#
# This is a demo of using Nix to manage packages for a program in a language agnostic way.
# If you run this example as an executable, it'll Just Work, even if you don't have Flask or emoji installed. Try it out!
#
# $ curl https://nixos.org/nix/install | sh
# $ chmod a+x nix_and_python.py
# $ ./nix_and_python.py
from flask import Flask
#!/bin/bash
# http://stackoverflow.com/questions/8175000/parsing-arguments-options-flags-in-a-bash-script
base_url=""
client_id=""
origin=""
password=""
username=""
verbose=0
@jpf
jpf / output.sh
Created March 7, 2016 22:26
Don't hate: cavitate
$ for w in `cat /usr/share/dict/words | egrep 'ate$'`; do echo "Don't hate: ${w}"; done
Don't hate: abacate
Don't hate: abacinate
Don't hate: abalienate
Don't hate: abate
Don't hate: abbreviate
Don't hate: abdicate
Don't hate: aberrate
Don't hate: abietate
Don't hate: abintestate
@jpf
jpf / CFBundleVersion.py
Created December 2, 2013 23:16
Given a list of Mac OS X Applications, print out their names and version numbers.
import os
import plistlib
import argparse
class CFBundle:
def __init__(self, path, kind='path'):
self.name = False
self.version = False
@jpf
jpf / hangup-and-text.xml
Last active December 21, 2015 08:09
TwiML that will answer a call, read a message saying to text instead, and also send a text message.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Hello. I don't answer voice calls, please text me instead.</Say>
<Pause length="2"/>
<Hangup/>
<Sms>Trying to get ahold of me? Reply to this text!</Sms>
</Response>
@jpf
jpf / filegenerator.py
Created June 20, 2013 09:03
I'm using this code to stream a file from Flask as that file is being written.
from Queue import Queue
from time import sleep
import threading
class FileGenerator(object):
def __init__(self):
self.q = Queue()
def read_generator(self):