Skip to content

Instantly share code, notes, and snippets.

View bradclawsie's full-sized avatar

Brad Clawsie bradclawsie

View GitHub Profile
@bradclawsie
bradclawsie / loaddictionary.hs
Created December 26, 2011 08:49
loaddictionary.hs
module Main where
import qualified Data.List as L
import qualified Control.Monad as C
import qualified Network.Memcache as MC
import qualified Network.Memcache.Protocol as S
setword conn word = do
success <- MC.set conn word (1 :: Int)
C.when (success == False) $ print word
return success
@bradclawsie
bradclawsie / loaddictionary.rkt
Created December 24, 2011 08:18
loaddictionary.rkt
#lang racket
(require (planet "memcached.rkt" ("jaymccarthy" "memcached.plt" 1 0)))
(define loaddict
(lambda (fn)
(letrec (;; our input handle
[in (open-input-file fn)]
;; our memcache conn
[mc (memcached "localhost" 11212)]
;; our function for walking the file
@bradclawsie
bradclawsie / loaddictionary.pl
Created December 24, 2011 08:15
loaddictionary.pl
#!/usr/bin/env perl
use v5.12;
use warnings;
use strict;
use Cache::Memcached;
my $memd = Cache::Memcached->new();
$memd->set_servers(["localhost:11212"]);
open(my $fh,"<","/usr/share/dict/words") || die "open $!";
my $line = <$fh>; # get rid of first empty line
@bradclawsie
bradclawsie / ubs.hs
Created September 10, 2011 06:28
haskell code to find all such four-digit numbers (except 0000)
module Main where
import Char
f a1 a2 b1 b2 =
(a1 == (((a2 + b2 - b1) / 10.0) + b1 - a2) * (-1.0)) &&
(a2 == ((a2 - a1 - b1) * 10.0) - b2 + b1) &&
(b1 == (((a2 - a1 - b1) * 10.0) - a2 - b2) * (-1.0)) &&
(b2 == ((a2 - a1 - b1) * 10) - a2 + b1)
-- first line transforms 1978 -> [1.0,9.0,7.0,8.0]
@bradclawsie
bradclawsie / .csirc
Created August 15, 2011 04:52
.csirc
(use readline regex)
(current-input-port (make-gnu-readline-port))
(gnu-history-install-file-manager (string-append (or (get-environment-variable "HOME") ".") "/.csi.history"))
@bradclawsie
bradclawsie / dotemacs-php.el
Created July 12, 2011 20:29
hooking into the php mode in emacs
;; php
(load "~/.el/lang/php-mode.el")
(defun my-php-mode-hook ()
(c-set-offset 'substatement-open 0)
(c-set-offset 'statement-case-open 0)
(c-set-offset 'case-label '+)
(setq tab-width 4)
(setq c-basic-offset 4)
(setq c-auto-newline nil)
(setq indent-tabs-mode nil)
@bradclawsie
bradclawsie / rmtrail.el
Created July 12, 2011 20:17
remove all newlines after text in elisp
(defun php-delete-trailing-blank-lines ()
"Deletes all blank lines at the end of the file."
(interactive)
(save-excursion
(save-restriction
(widen)
(goto-char (point-max))
(delete-blank-lines)
(let ((trailnewlines (abs (skip-chars-backward "\n\t"))))
(if (> trailnewlines 0)
@bradclawsie
bradclawsie / getpw.pl
Created July 11, 2011 05:50
getpw.pl
#!/usr/bin/env perl
use v5.14;
use warnings;
use strict;
# this is my password file. yours may be different
my $pwfile = $ENV{'HOME'} . '/git/docs/pw/pw.txt.asc';
die $pwfile . ' not readable?' unless (-r $pwfile);
# search term required
@bradclawsie
bradclawsie / simpleaes.hs
Created May 13, 2011 18:39
minimal simpleAES example
module Main (main) where
import Codec.Crypto.SimpleAES
import Data.ByteString.Lazy as L
import Data.ByteString.Lazy.Char8 as L8
import Data.ByteString.Char8 as B8
main = do
let lstr = L.concat [L8.pack "hi there"]
pw = B8.pack "abc123abc1234567"
lencode2 <- encryptMsg CBC pw lstr
@bradclawsie
bradclawsie / pw.hs
Created May 9, 2011 06:03
haskell pw prompt
module Main where
import System.IO
import Data.Char
import System.Console.ANSI
-- ord val of 10 is return key
getPW = getPW' "" where
getPW' s = getChar >>= \x ->
if ((ord x) == 10) then return s
else cursorBackward 1 >> putStr "*" >> getPW' (s ++ [x])