Skip to content

Instantly share code, notes, and snippets.

View beppu's full-sized avatar

John Beppu beppu

View GitHub Profile
#!/bin/sh
# Quick start-stop-daemon example, derived from Debian /etc/init.d/ssh
set -e
NAME=ip_monster
PIDFILE=/var/run/$NAME.pid
LOG="/var/log/$NAME.log"
@beppu
beppu / p53-longest-increasing-sub-seq.clj
Created November 30, 2013 04:02
4clojure problem #53
; 2013-11-29 SOLVED
(defn p53-longest-increasing-sub-seq [s]
(let [begin-sequences
(fn [s] (rest (reductions (fn [a b] (conj a b)) [] s)))
end-sequences
(fn [s] (reverse (reduce (fn [mem a] (conj (map (fn [b] (flatten [b a])) mem) (list a))) [] s)))
longest
(fn [s] (reduce (fn [longest x] (if (> (count x) (count longest)) x longest)) [] s))]
(->> (apply concat (map begin-sequences (end-sequences s)))
(filter (fn [s] (apply < s)))
@beppu
beppu / make-perl-deb
Last active December 29, 2015 04:09
notes for making a customized perl .deb
#!/bin/sh
# step 1 - compile perl {{{
/root/perl5/perlbrew/perls/perl-5.16.3/bin/perl /root/p/bin/perlbrew install perl-5.18.1 --notest -Dusethreads -Duselargefiles -Dcccdlflags=-fPIC -Dpager=/usr/bin/sensible-pager -Doptimize=-O2 -Duseshrplib -Dcf_by=Dave [email protected] -Duse64bitall -Darchname=x86_64-linux-gnu -Dccflags=-DDEBIAN
# }}}
# step 2 - install cpan modules with newly compiled perl {{{
PERL5=/root/perl5/perlbrew/perls/perl-5.18.1
@beppu
beppu / upsert.ls
Created October 30, 2013 00:24
upsert function (and associated helper functions) written in livescript
insert-statement = (table, obj) ->
columns = keys obj
value-set = [ "$#{i+1}" for k,i in columns ].join ', '
vals = values obj
return ["INSERT INTO #table (#columns) VALUES (#value-set) RETURNING *", vals]
update-statement = (table, obj, wh) ->
wh ?= "WHERE id = $1"
ks = keys obj |> filter (-> it isnt \id)
obj-vals = [ obj[k] for k in ks ]
@beppu
beppu / js_init.php.js
Created November 13, 2011 20:00
js interspersed with php warnings
<br />
<b>Notice</b>: Undefined index: session_userid in <b>/Users/beppu/src/github.com/asg/top.php</b> on line <b>29</b><br />
<br />
<b>Notice</b>: Undefined index: id in <b>/Users/beppu/src/github.com/asg/top.php</b> on line <b>38</b><br />
<br />
<b>Notice</b>: Undefined index: current_document in <b>/Users/beppu/src/github.com/asg/top.php</b> on line <b>39</b><br />
<br />
<b>Notice</b>: Undefined index: javascript_doc_id in <b>/Users/beppu/src/github.com/asg/top.php</b> on line <b>65</b><br />
<br />
<b>Notice</b>: Undefined index: session_accessLevel in <b>/Users/beppu/src/github.com/asg/top.php</b> on line <b>70</b><br />
@beppu
beppu / video.google.com-download
Created April 23, 2011 11:51
on STDIN, give this script a list of google video urls, and it will download them.
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::Simple;
use URI;
use URI::QueryParam;
use URI::Escape;
while(<>) {
my ($url, $title) = split(/\|/);
@beppu
beppu / async-soap-requests.pl
Created March 16, 2011 20:34
Can SOAP::Lite be tricked into being AnyEvent+Coro-friendly?
#!/usr/bin/env perl
use common::sense;
use AnyEvent;
use Coro;
use AnyEvent::HTTP::LWP::UserAgent;
use SOAP::Lite; # +trace => 'all';
use SOAP::Transport::HTTP; # preload it so that we can set USERAGENT_CLASS reliably;
my @results;
@beppu
beppu / path.txt
Created January 17, 2011 08:04
Joyent SmartMachine Node Info
[node@metanotes ~]$ perl -M5.10.0 -e 'say join("\n", split(":", $ENV{PATH}))' | xargs ls > path.txt
/home/node/local/bin:
npm
[email protected]
/home/node/local/nodejs/bin:
node
node_g
node-repl
node-waf
@beppu
beppu / fuck-internet-explorer.txt
Created January 13, 2011 21:36
notice the 0s in the day column
mysql> select * from purchase_item where purchase_id = 2;
+----+-------------+-----+---------+------------+-------------+-------+---------------------+---------------------+
| id | purchase_id | day | t | child_name | child_grade | price | created_on | modified_on |
+----+-------------+-----+---------+------------+-------------+-------+---------------------+---------------------+
| 37 | 2 | 0 | regular | Bill | 0 | 5.00 | 2011-01-13 13:08:56 | 2011-01-13 15:08:56 |
| 38 | 2 | 0 | regular | Bill | 0 | 5.00 | 2011-01-13 13:08:56 | 2011-01-13 15:08:56 |
| 39 | 2 | 0 | regular | Bill | 0 | 5.00 | 2011-01-13 13:08:56 | 2011-01-13 15:08:56 |
| 40 | 2 | 0 | regular | Bill | 0 | 5.00 | 2011-01-13 13:08:56 | 2011-01-13 15:08:56 |
| 41 | 2 | 0 | regular | Bill | 0 | 5.00 | 2011-01-13 13:08:56 | 2011-01-13 15:08:56 |
| 42 | 2 | 0 | regula
@beppu
beppu / block
Created November 29, 2010 22:20
Generate a list of nginx deny statements for a given country.
#!/usr/bin/perl
use strict;
use warnings;
my $country = shift;
die("Usage: block <COUNTRY>\n") unless $country;
# Examples:
# block Russia < GeoIPCountryWhois.csv > deny_russia.list
# block Poland < GeoIPCountryWhois.csv > deny_poland.list
#