Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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) {
#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 / pascal.hs
Created April 17, 2012 22:26
I'm an ass.
pascal' :: [Int] -> [Int]
pascal' l
| length l < 2 = [1]
| otherwise = (a + b) : (pascal' (b:rest))
where a:(b:rest) = l
pascal :: [Int] -> [Int]
pascal = (1:) . pascal'
npto :: (Integral a) => a -> [a]
npto x = [2,3] ++ concat [[x*6-1,x*6+1] | x <- [1..n]]
where n = ((+1) . round . sqrt . fromIntegral $ x) `div` 6
factors :: (Integral a) => a -> [a]
factors 1 = []
factors x = least : factors (x `div` least)
where least = head $ fs ++ [x]
fs = filter ((==0) . mod x) . npto $ x
package Magento;
use v5.14;
use warnings;
use Carp;
use XML::RPC;
sub new {
my ($class,$uri,$user,$pass) = @_;
my $client = XML::RPC->new("$uri/api/xmlrpc/");
@tron1point0
tron1point0 / Makefile
Created June 7, 2012 00:07
Youtube thingie
VERSION := 4.1.0
ZIPFILE := ext-$(VERSION)-gpl.zip
download := http://cdn.sencha.io/$(ZIPFILE)
downloader := $(shell which curl)
downloader ?= $(shell which wget)
COFFEE := $(shell which coffee)
UNZIP := $(shell which unzip)
#include <stdlib.h>
#define lc(var) (var >= 'A' && var <= 'Z' ? var + 32 : var)
#define uc(var) (var >= 'a' && var <= 'z' ? var - 32 : var)
#define vowelp(var) ( \
uc(var) == 'A' || \
uc(var) == 'E' || \
uc(var) == 'I' || \
uc(var) == 'O' || \
uc(var) == 'U')