Skip to content

Instantly share code, notes, and snippets.

View wpbonelli's full-sized avatar

wpbonelli

  • UCAR / @usgs
  • 05:13 (UTC -05:00)
View GitHub Profile
@elnygren
elnygren / expression_problem.clj
Last active January 23, 2025 16:00
Solving the Expression Problem with Clojure
; The Expression Problem and my sources:
; http://stackoverflow.com/questions/3596366/what-is-the-expression-problem
; http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/
; http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/
; http://www.ibm.com/developerworks/library/j-clojure-protocols/
; To begin demonstrating the problem, we first need some
; "legacy code" with datastructures and functionality:
@olih
olih / jq-cheetsheet.md
Last active December 5, 2025 21:17
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@mgold
mgold / README.md
Last active August 28, 2021 19:20
Spherical Coordinates

Grab the brown and black knobs. You can also dial some of the numbers on the right.

Spherical coordinates are defined by ρ (rho, the distance from the origin), θ (theta, rotation parallel to the xy-plane), and φ (phi, inclination from the north pole to the south pole). This interactive drawing shows how they relate to the Cartesian xyz coordinates. The key is the horizontal slice of radius r.

  • z = ρ cos φ
  • r = ρ sin φ

Which makes sense: when φ=0, we're looking at the north pole, z=ρ and r=0. Then we're left with the familiar equations:

  • x = r cos θ
@ZedThree
ZedThree / fortran-dot-graph.py
Last active February 2, 2023 21:15
Build a dot graph of the Fortran modules in a list of files.
import re
def build_graph(files,exclude=['hdf5','h5lt','mpi']):
"""Build a dot graph of the Fortran modules in a list of files,
excluding modules named in the list exclude"""
# Start the graph
graph = "digraph G {\n"
deps = {}
p = re.compile("^(?:module|program) ([a-zA-Z0-9_]*)",
@hrldcpr
hrldcpr / tree.md
Last active December 17, 2025 03:44
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@igniteflow
igniteflow / git_python_current_branch.py
Created February 7, 2012 17:33
GitPython get current active branch
"""
Gets the name of the active Git branch as a string.
Depends on GitPython
pip install GitPython
"""
from git import Repo
repo = Repo('/path/to/your/repo')
branch = repo.active_branch
@audy
audy / shannon.py
Created January 17, 2011 17:28
Shannon Diversity Index
#!/usr/bin/env python
# Shannon Diversity Index
# http://en.wikipedia.org/wiki/Shannon_index
import sys
def sdi(data):
""" Given a hash { 'species': count } , returns the SDI
@jagregory
jagregory / gist:710671
Created November 22, 2010 21:01
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork [email protected]