Skip to content

Instantly share code, notes, and snippets.

View wcaleb's full-sized avatar

W. Caleb McDaniel wcaleb

View GitHub Profile
@bearfrieze
bearfrieze / comprehensions.md
Last active December 23, 2023 22:49
Comprehensions in Python the Jedi way

Comprehensions in Python the Jedi way

by Bjørn Friese

Beautiful is better than ugly. Explicit is better than implicit.

-- The Zen of Python

I frequently deal with collections of things in the programs I write. Collections of droids, jedis, planets, lightsabers, starfighters, etc. When programming in Python, these collections of things are usually represented as lists, sets and dictionaries. Oftentimes, what I want to do with collections is to transform them in various ways. Comprehensions is a powerful syntax for doing just that. I use them extensively, and it's one of the things that keep me coming back to Python. Let me show you a few examples of the incredible usefulness of comprehensions.

#! /usr/bin/env python
import git
from time import localtime, strftime
from subprocess import call
crime = git.Repo("/Users/chadblack/Projects/crime")
call(["jrnl",strftime("%H:%M", localtime(crime.head.commit.committed_date))+":",crime.head.commit.message,"@"+crime.description])
@hadley
hadley / advise.md
Created February 13, 2015 21:32
Advise for teaching an R workshop

I think the two most important messages that people can get from a short course are:

a) the material is important and worthwhile to learn (even if it's challenging), and b) it's possible to learn it!

For those reasons, I usually start by diving as quickly as possible into visualisation. I think it's a bad idea to start by explicitly teaching programming concepts (like data structures), because the pay off isn't obvious. If you start with visualisation, the pay off is really obvious and people are more motivated to push past any initial teething problems. In stat405, I used to start with some very basic templates that got people up and running with scatterplots and histograms - they wouldn't necessary understand the code, but they'd know which bits could be varied for different effects.

Apart from visualisation, I think the two most important topics to cover are tidy data (i.e. http://www.jstatsoft.org/v59/i10/ + tidyr) and data manipulation (dplyr). These are both important for when people go off and apply

@omz
omz / Dropbox File Picker.py
Last active May 17, 2020 21:47
Dropbox File Picker.py
# IMPORTANT SETUP INSTRUCTIONS:
#
# 1. Go to http://www.dropbox.com/developers/apps (log in if necessary)
# 2. Select "Create App"
# 3. Select the following settings:
# * "Dropbox API app"
# * "Files and datastores"
# * "(No) My app needs access to files already on Dropbox"
# * "All file types"
# * (Choose any app name)
@lmullen
lmullen / index.html
Last active August 29, 2015 13:57
Dissertation motivation
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundation/5.1.1/css/normalize.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundation/5.1.1/css/foundation.min.css">
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style>
p {
font-size: 18px;
@lmullen
lmullen / Rakefile
Last active August 29, 2015 13:57
Download the WPA Slave Narratives from the Library of Congress
desc "Download the WPA Slave Narratives using wget"
task :wget_wpa do
system %{wget --wait 1 --limit-rate=200k -A .jpg,.png,.gif,.txt,.tif,.pdf --no-parent --background --mirror http://memory.loc.gov/mss/mesn/}
end
@mateuszgachowski-snippets
mateuszgachowski-snippets / itunes.sh
Created December 6, 2013 22:19
Bash: iTunes CLI
#!/bin/sh
#
####################################
# iTunes Command Line Control v1.0
# written by David Schlosnagle
# created 2001.11.08
# @edited Mateusz Gachowski
####################################
showHelp () {
@reinholdsson
reinholdsson / Makefile
Last active December 18, 2020 17:04
RMarkdown to PDF with pandoc (using Makefile)
build:
Rscript build.r
clean:
rm -rf *.tex *.tex-e *.bbl *.blg *.aux *.out *.log *.spl plots/ cache/ *.gz\(busy\) *.gz *.pdf
@lmullen
lmullen / ToggleFootnoteJumping.vim
Created April 3, 2013 13:47
Jump between footnote markers with Vim's * key
" Find related Pandoc footnote numbers
" -------------------------------------------------------------------
" Vim's * key searches for the next instance of the word under the
" cursor; Vim decides what counts as the boundary of a word with the
" iskeyword option. This function toggles the special characters of a
" Pandoc footnote in the form [^1] to allow you to jump between
" footnotes with the * key.
nnoremap _fn :call ToggleFootnoteJumping()<CR>
function! ToggleFootnoteJumping()
if exists("g:FootnoteJumping")
@johnjohndoe
johnjohndoe / pre-commit.sh
Created November 6, 2012 11:48
Git pre-commit hook to add a new line at the end of a file and remove trailing whitespaces
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# Usage:
# Remove the .sh file extension when you put the script in your hooks folder!
#