Skip to content

Instantly share code, notes, and snippets.

#ifdef STANDARD
#include <string.h>
#include <stdlib.h>
#include <time.h>
#else
#include <my_global.h>
#include <my_sys.h>
#endif
#include <mysql.h>
#include <m_ctype.h>
@tron1point0
tron1point0 / sqlconnect.pl
Created April 11, 2012 16:27
Connect to dancer's dev DB
#!/usr/bin/env perl
use v5.14;
use warnings;
use YAML::XS qw(Load);
my @files = qw(config.yml environments/development.yml);
unshift @files, @ARGV if @ARGV;
for (@files) {
@tron1point0
tron1point0 / queued.pl
Created April 3, 2012 22:06
It's *like* redis...
#!/usr/bin/env perl
use v5.14;
use warnings;
package Handler::Send;
use base 'Tatsumaki::Handler';
sub post {
my ($self,$id) = @_;
@tron1point0
tron1point0 / todo.pl
Created March 31, 2012 14:58
Redmine TODO list
#!/usr/bin/env perl
use v5.14;
use warnings;
use LWP::UserAgent;
use List::MoreUtils qw(part);
use YAML qw(LoadFile);
use JSON::XS qw(decode_json);
use Text::FormatTable;
@tron1point0
tron1point0 / nqueens.hs
Created March 12, 2012 22:47
N-queens solver
import Data.List
import Data.Maybe
import Data.Monoid
-- The hard stuff
solve' :: Int -> [(Int, Int)] -> [(Int, Int)] -> Solutions
solve' nq queens board
| length queens == nq = Solutions [Solution nq queens]
| length board == 0 = mempty
@tron1point0
tron1point0 / planetary-interaction.hs
Created March 9, 2012 23:55
Look, ma, I made a database with a query language!
import Data.List
import Data.Maybe
input x = map (\(a,b) -> (a, b * x))
reduce :: [([Char], Integer)] -> [([Char], Integer)]
reduce = map (\(a,b) -> (head a, sum b)) . map (unzip) . group . sort
planet n = map (\(a,_) -> (n,a))
planets_for = foldl1
(\a b ->
@tron1point0
tron1point0 / dotlan.js
Created March 2, 2012 21:06
dotlan functions
// Raw SVG: http://evemaps.dotlan.net/svg/Branch.dark.svg
function system(name,fn) {
document.getElementsByClassName('ss').each(function(elem){
if(elem.textContent == name) fn.call(elem.parentElement)
});
}
system('D4R-H7',function(){this.getElementsByClassName('s')[0].style.fill = '#000000'});
@tron1point0
tron1point0 / epoch.pl
Created March 2, 2012 16:03
You type stuff as arguments, it gives you the local time
#!/usr/bin/env perl
use v5.14;
use warnings;
use Time::Format qw(time_format);
use Time::ParseDate;
die <<END if $ARGV[0] && $ARGV[0] =~ m/-h(?:elp)?/;
$0: Fuzzy time conversion to localtime
@tron1point0
tron1point0 / knapsack.hs
Created May 8, 2014 20:02
Bounded knapsack problem
import Data.List
type Weight = Int
type Value = Int
type Item = (String,Weight,Value)
type Pack = ([String],Weight,Value)
knapsack :: (Pack -> Bool) -> [Item] -> [Pack]
knapsack f = sortBy (value) . filter (f) . map (foldl (pack) ([],0,0)) . tail . subsequences
where value (_,_,v1) (_,_,v2) = compare v2 v1
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Formatter;
public class Machine {
private Tape<Integer>[] tapes;
private int[] memory;
private final int scratch; // index of the scratch tape