Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / websetup.md
Last active October 3, 2015 17:46
Setting up a local LAMP web server on OS X

Spinning up a local web server on OS X shouldn't be difficult, but it's a little fussy. This is a reminder list.

MySQL

Install MySQL

Update the path of the mysql socket. This fixes an OS X bug.

If you have a file at /tmp/mysql.sock but none at /var/mysql/mysql.sock, then:

@fitnr
fitnr / index.html
Last active August 29, 2015 14:03
demo of styled gmap
<html>
<head>
<title>map test</title>
<script></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDa40kHQjrMVADweLvXIVaJUjXOUraG164"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="styled-map.js" type="text/javascript"></script>
</head>
<body>
@fitnr
fitnr / index.html
Created July 2, 2014 19:17
Tinymouse - a simple tinymce editor to have on hand
<html>
<head>
<title>TinyMouse</title>
<!-- TinyMCE -->
<script type="text/javascript" src="tinymce-dist/tinymce.min.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "exact",
elements: "elm1",
theme : "modern",