Skip to content

Instantly share code, notes, and snippets.

To merge repo history in, define the following shell function:
function git-add-repo
{
repo="$1"
dir="$(echo "$2" | sed 's/\/$//')"
pwd="$(pwd)"
tmp="$(mktemp -d)"
remote="$(echo "$tmp" | sed 's/\///g'| sed 's/\./_/g')"
On the matter of "1 + 1/2 + 1/4 + 1/8..." really is the same as "two"
So, let's assign the answer (whatever it is) to x:
x = 1+ 1/2 + 1/4 + 1/8 + ...
Now let's take away one
x - 1 = 1/2 + 1/4 + 1/8 + ...
Now let's double both sides
2x - 2 = 1 + 1/2 + 1/4 + 1/8 + ...
@oneandoneis2
oneandoneis2 / params.sh
Created December 2, 2016 09:56
Params with default values in Bash
#!/bin/bash
# Default param values
foo=${1:-"The first entry"}
bar=${2:-"The second entry"}
echo $foo
echo $bar
#!/usr/bin/perl
# Author: Todd Larason <jtl@molehill.org>
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.2 2002/03/26 01:46:43 dickey Exp $
# use the resources for colors 0-15 - usually more-or-less a
# reproduction of the standard ANSI colors, but possibly more
# pleasing shades
# colors 16-231 are a 6x6x6 color cube
for ($red = 0; $red < 6; $red++) {
@oneandoneis2
oneandoneis2 / gist:9f319ce50895e144a91b0a85851dad55
Created September 25, 2016 09:16
Lispy list iteration in Perl
#!/usr/bin/env perl
# Lisp-like lists in perl, made entirely out of functions.
sub cons { my ($h,$t)=@_; return sub{ $fn=shift;$fn->($h,$t)} }
sub head { my $lst=shift; $lst->( sub{ my($h,$t)=@_; return $h} );}
sub tail { my $lst=shift; $lst->( sub{ my($h,$t)=@_; return $t} );}
sub list { my $thing = shift; if (defined $thing) { return cons($thing, list(@_)) } }
sub listmap {
my ($fn,$lst)=@_;
@oneandoneis2
oneandoneis2 / gist:c43b77f468454637a1b09ebaf34150b8
Created July 21, 2016 14:42
Why would you want to return more than one value from a function when you have this simple alternative??
(define (split src fn)
(if (null? src)
(fn '() '())
(split (cdr src)
(lambda (letters numbers)
(let ((next (car src)))
(if (number? next)
(fn letters (cons next numbers))
(fn (cons next letters) numbers)))))))
@oneandoneis2
oneandoneis2 / gist:3162ac298b9052f026e8
Created March 9, 2015 17:46
Trivial demo of why not to blindly rebase
Original code:
$c->{stash}{this} = thing();
$c->{stash}{that} = thing();
$c->{stash}{the_other} = thing();
some_code();
------------------------------------------------------------------------------
Your changes:
ⓉⓊⒾⓉ
@oneandoneis2
oneandoneis2 / gist:15170aae2c9c3b1294fa
Created January 23, 2015 11:44
Save as .git/hooks/pre-commit in your puppet repo to ensure valid syntax in .pp and .erb files
#!/bin/sh
# Override error checking so we can commit WIP or whatever with
# JFDI=1 git commit ....
if [ "0$JFDI" -eq 1 ]; then
exit 0
fi
# Redirect output to stderr.
exec 1>&2
#! /bin/sh
# Clear wallpaper first
xsetroot -solid black
while [ 1 ]
do
date
# Generate current Earth & Moon images
xplanet -body moon -geometry 300x300 -num_times 1 \