Skip to content

Instantly share code, notes, and snippets.

@fitnr
fitnr / jquery-getelementbyid.js
Last active August 29, 2015 14:04
Tired of that extra '#' you need to specify an element's id in jQuery, compared to document.getElementById? Just add this to your code and use $.getElementById('foo')! Easy as pie!
// this is satire, do not use in real life
jQuery.getElementById = function(id) {
return jQuery('#' + id);
};
@fitnr
fitnr / setup
Last active August 29, 2015 14:07
Steps I just went through to set up a new CentOS 7 box, for possible future edification
# set up a non-root user
# below commands assume you're running from root
useradd <USER>
passwd <USER>
# install another python
yum -y update
yum groupinstall -y 'development tools'
yum install python-devel
# maybe don't need this?
@fitnr
fitnr / readme.md
Last active December 17, 2018 09:14
Bookmarklet for switching between two versions of a site, say dev and production, or localhost and dev

How to

Change the left_domain_name and right_domain_name variables to reflect your project. If your sites have exactly matching URL schemas (where localhost/my/path is always equivalent to production.com/my/path), you can ignore that big comment block. If not, check it out and rewrite the two functions to fit your setup.

Compress the javascript, say with UglifyJS.

Urlencode the result, say with this tool.

Add javascript: to the front and save it as a bookmark. Depending on your browser, the easiest way to do this might be to make a new bookmark for a random page and then edit both the address and name.

@fitnr
fitnr / complete_graph.py
Last active August 29, 2015 14:08
Create a complete graph of lines between a set of points in QGIS
from itertools import combinations
# get the active layer
inlayer = iface.activeLayer()
# Get the index of the NAME field, then rewind the list
infeatures = inlayer.getFeatures()
eg = infeatures.next()
i = eg.fields().indexFromName('NAME')
infeatures.rewind()
@fitnr
fitnr / git-archive-file.sh
Last active December 4, 2015 23:42
Great a nicely-named archive file from your git repository
#!/bin/bash
# Save this somewhere in your path as "git-archive-file"
# and do 'chmod u+x git-archive-file'
# If run at tag "v10.0", archvie file will be named "repo-v10.0.zip"
# If run after one commit after a tag, file will be named "repo.v10.0-1-gdc03bc1.branchname.zip"
# adapted from
# http://blog.thehippo.de/2012/03/tools-and-software/how-to-create-a-custom-git-command-extension/
@fitnr
fitnr / index.html
Last active December 18, 2016 02:56
Hypocycloids
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>hypotrochoids or epitrochoid</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="https://raw.githubusercontent.com/mbostock/d3/master/lib/colorbrewer/colorbrewer.js"></script>
<style type="text/css">
.hypo {
fill: none;
@fitnr
fitnr / abs_filename.sh
Created January 8, 2015 17:14
Bash script to get an absolute filename from a relative filename
#!/bin/sh
# $1 : relative filename
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
@fitnr
fitnr / table2csv.js
Created January 30, 2015 17:47
convert table to csv (uses JQuery)
// encoded:
// javascript:(function()%7B$('table').each(function()%7Bvar%20$table=$(this);$('%3Ctextarea%3E').css('width',$table.width()).css('height','400px').html($.map($table.find('tr'),function(tr)%7Breturn%20$.map($(tr).find('th,%20td'),function(e)%7Breturn'%22'+$(e).text().replace('%22','%22%22').replace('%5Cn','%20')+'%22'%7D).join(',')%7D).join('&%2313;&%2310;')).insertAfter($table);%7D)%7D)()
javascript:(function() {
$('table').each(function() {
var $table = $(this);
$('<textarea>').css('width', $table.width())
.css('height', '400px')
.html(
$.map(
$table.find('tr'), function(tr) {

Keybase proof

I hereby claim:

  • I am fitnr on github.
  • I am fitnr (https://keybase.io/fitnr) on keybase.
  • I have a public key whose fingerprint is 74E5 F1EE 04D6 968C DA8A 3E81 3ABA FB3A 1D61 8BDC

To claim this, I am signing this object:

@fitnr
fitnr / fips2states.sh
Last active July 31, 2022 01:01
Replace US states with their FIPS code or postal code or vis/versa
#!/bin/bash
# Replace FIPS codes with US states/^territory names
# usage: sh fips2state2.sh inputfile.txt > outputfile.txt
# or just copy everything but the '$1' and run on the command line
sed -e 's/^54/West Virginia/' -e 's/^02/Alaska/' -e 's/^01/Alabama/' -e 's/^05/Arkansas/' -e 's/^60/American Samoa/' \
-e 's/^04/Arizona/' -e 's/^06/California/' -e 's/^08/Colorado/' -e 's/^09/Connecticut/' -e 's/^11/District of Columbia/' \
-e 's/^10/Delaware/' -e 's/^12/Florida/' -e 's/^13/Georgia/' -e 's/^66/Guam/' -e 's/^15/Hawaii/' \
-e 's/^19/Iowa/' -e 's/^16/Idaho/' -e 's/^17/Illinois/' -e 's/^18/Indiana/' -e 's/^20/Kansas/' \
-e 's/^21/Kentucky/' -e 's/^22/Louisiana/' -e 's/^25/Massachusetts/' -e 's/^24/Maryland/' -e 's/^23/Maine/' \
-e 's/^26/Michigan/' -e 's/^27/Minnesota/' -e 's/^29/Missouri/' -e 's/^28/Mississippi/' -e 's/^30/Montana/' \