Skip to content

Instantly share code, notes, and snippets.

View kliph's full-sized avatar

Cliff Rodgers kliph

  • Philadelphia, PA
View GitHub Profile
@kliph
kliph / gist:3042535
Created July 3, 2012 19:55
possibly broken starfield animation
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
# from: https://lorenzod8n.wordpress.com/2007/05/25/pygame-tutorial-1-getting-started/
import pygame
import pdb
from random import randrange, choice
x = y = 0
running = 1
@kliph
kliph / jamar.el
Created April 16, 2013 19:10
It's simple mathematics.
;;; jamar.el --- What's the math?
;; Copyright (C) 2013 Cliff Rodgers
;; Author: Cliff Rodgers <cliff.rodgers@gmail.com>
;; Keywords: news, calendar, games
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
(defun wrap-region-in-md-kbd-tags ()
"Wraps the selected region in HTML keyboard (<kbd></kbd>) tags
to create keyboard glyphs."
(interactive "r")
(save-excursion
(narrow-to-region (region-beginning) (region-end))
(goto-char (point-min))
(insert "<kbd>")
(goto-char (point-max))
(insert "</kbd>")
@kliph
kliph / gist:6708917
Created September 26, 2013 02:12
The raw .org source for a blog post on links with the o-blog blog generator.
* DONE Links with o-blog :o@blog:org@mode:emacs:
CLOSED: [2013-09-25 Wed 20:13]
Links are easily embedded into [[http://orgmode.org/][org-mode]] documents. Simply type =C-c
C-l= and enter =http://linkblah.com= at the prompt. Org-mode supports
a variety of [[http://orgmode.org/manual/External-links.html][link prefix types]].
[[https://github.com/renard/o-blog][O-blog]] is slightly more complicated.
You can follow along by reading the raw =.org= source in this gist.
@kliph
kliph / gist:6928915
Last active December 25, 2015 05:59
Hacky method to open Mac OS X applications from the python command line
import os
os.system("open -a Microsoft\ PowerPoint") # For example.
os.system("open -a Preview ~/Desktop/printme.png") # And it works with
# file arguments
# too.
@kliph
kliph / gist:7914833
Created December 11, 2013 17:33
A little Clojure function to filter a list by some predicate and divide it into those elements for which the predicate is true and those elements for which the predicate is not true.
(defn filter-by [pred coll]
(let [grouped-map (group-by pred coll)
{true-list true
false-list false} grouped-map]
(merge [true-list false-list])))
(= '[[1 3 5 7 9] [0 2 4 6 8]] (filter-by odd? (range 10)))
(defvar R1)
(defvar R2)
(defvar R3)
(defvar R4)
(defun snesrand (&optional seed)
"Based on
https://github.com/optixx/snes/blob/master/libs/RANDOM.ASM "
(cond (seed
(setq R1 (ash seed -12))
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
@kliph
kliph / gist:e85046d788362c1ce0bb
Created December 3, 2014 03:15
Sampling without replacement in Clojure
(defn sample-without-replacement [coll]
"Returns a tuple in which the first value is the sample and the
second is a collection of the left over values. Does not preserve
the order of the input collection."
(let [shuffled (shuffle coll)
sample (last shuffled)
rest (pop shuffled)]
[sample rest]))