Skip to content

Instantly share code, notes, and snippets.

View beppu's full-sized avatar

John Beppu beppu

View GitHub Profile
@beppu
beppu / imgur
Created October 27, 2010 10:00
If you ever need to bulk upload many URLs to imgur.com, this is the tool for you.
#!/usr/bin/env perl
use common::sense;
use AnyEvent;
use AnyEvent::HTTP;
use JSON;
# Get your API key here:
# http://imgur.com/register/api_anon
my $imgur_api_key = '69696969696969696969696969696969'; # XXX - replace me
my $imgur_upload = 'http://api.imgur.com/2/upload.json';
@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
#
{
"created_at": "Mon Jan 01 16:02:46 +0000 2018",
"id": 947860662130110500,
"id_str": "947860662130110464",
"text": "Coin of the week; https://t.co/p55OUIL9qC",
"display_text_range": [
0,
17
],
"source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>",
Tue Dec 26 13:59:51 +0000 2017 | officialmcafee 961445378 | Coin Of The Day: https://t.co/WSTXaha1Nk
[ 'Coin Of The Day: https',
'https',
index: 0,
input: 'Coin Of The Day: https://t.co/WSTXaha1Nk' ]
COIN OF THE DAY! Coin Of The Day: https://t.co/WSTXaha1Nk { found: false,
reason: 'Couldn\'t find https in currencies list.' }
{ found: false,
reason: 'Couldn\'t find https in currencies list.' }
Mon Dec 25 13:59:59 +0000 2017 | officialmcafee 961445378 | Coin of the day: Humaniq (HMQ). In the spirit of Christmas, there is no better coin. Their mission is true to the v… https://t.co/aPoKRqBcqR
[ 'Coin of the day: Humaniq ',
'Humaniq ',
index: 0,
input: 'Coin of the day: Humaniq (HMQ). In the spirit of Christmas, there is no better coin. Their mission is true to the v… https://t.co/aPoKRqBcqR' ]
COIN OF THE DAY! Coin of the day: Humaniq (HMQ). In the spirit of Christmas, there is no better coin. Their mission is true to the v… https://t.co/aPoKRqBcqR { found: true, symbol: 'HMQ', name: 'Humaniq' }
attempting to buy HMQ
{ success: true,
message: '',
result:
$ bin/repl
> bot.btcSpend
0.001
> bot.btcSpend = 0.25
0.25
> bot.adjustment = 0.05
0.05
> bot.init()
Promise {
undefined,
@beppu
beppu / FileSaver.min.js
Last active December 8, 2016 20:42
Using FileSaver
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs=saveAs||function(e){"use strict";if(typeof e==="undefined"||typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),o="download"in r,a=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},i=/constructor/i.test(e.HTMLElement)||e.safari,f=/CriOS\/[\d]+/.test(navigator.userAgent),u=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},s="application/octet-stream",d=1e3*40,c=function(e){var t=function(){if(typeof e==="string"){n().revokeObjectURL(e)}else{e.remove()}};setTimeout(t,d)},l=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var o=e["on"+t[r]];if(typeof o==="function"){try{o.call(e,n||e)}catch(a){u(a)}}}},p=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob([String.fromChar
@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 -Dcf_email=dave@instantchannelinc.com -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 ]