Skip to content

Instantly share code, notes, and snippets.

(defun add-at (a l pos)
(if (= pos 0)
(cons a l)
(cons (car l) (add-at a (rest l) (1- pos)))))
(defun insert-everywhere/in-a-word (char word)
(loop for position from 0 to (length word)
collecting (add-at char word position)))
(defun insert-in-all (char word)
#!/usr/bin/env perl
use strict;
use warnings;
use threads;
my $num_thr = $ARGV[0] or die "Specify the number of threads first.\n";
my $rate = $ARGV[1] || 1;
my $contiune = 1;
@horus
horus / gist:1619365
Created January 16, 2012 06:19
Simple wrapper for FreeBSD pkg* commands (I HATE typing underscores!)
#!/usr/bin/perl
use strict;
use warnings;
sub AUTOLOAD {
( my $cmd = our $AUTOLOAD ) =~ s/.*:://;
for ( map { ; "$_/pkg_$cmd", "$_/pkg$cmd" } qw(/usr/sbin /usr/local/sbin) )
{
system( $_, @_ ) and last if -x;
diff --git a/Plugins/Purple Service/ESPurpleMSNAccount.m b/Plugins/Purple Service/ESPurpleMSNAccount.m
index 14f1b1d..29b8248 100644
--- a/Plugins/Purple Service/ESPurpleMSNAccount.m
+++ b/Plugins/Purple Service/ESPurpleMSNAccount.m
@@ -361,7 +361,8 @@
currentMaxNumberOfPreEncodedCharacters -= 10;
}
- purple_account_set_alias(account, friendlyNameUTF8String);
+ purple_account_set_alias(account, friendlyNameUTF8String);
@horus
horus / gist:3089085
Created July 11, 2012 08:46
updating haskell98 out for Network.XMPP
diff -ruN a/XMPP-0.1.2/Network/XMPP/Stanzas.hs b/XMPP-0.1.2/Network/XMPP/Stanzas.hs
--- a/XMPP-0.1.2/Network/XMPP/Stanzas.hs 2012-07-11 16:31:35.000000000 +0800
+++ b/XMPP-0.1.2/Network/XMPP/Stanzas.hs 2012-07-11 16:33:32.000000000 +0800
@@ -31,7 +31,7 @@
import Network.XMPP.XMLParse
import Network.XMPP.JID
import System.Random
-import Maybe
+import Data.Maybe
@horus
horus / gist:3780368
Created September 25, 2012 06:58
replaceMin problem & value recursion
{-# LANGUAGE DoRec #-}
data Tree a = L a | B (Tree a) (Tree a)
deriving (Show)
rpMinWithIO :: (Ord a, Show a) => (Tree a, a) -> IO (Tree a, a)
rpMinWithIO (L a, m) = print a >> return (L m, a)
rpMinWithIO (B l r, m) =
rpMinWithIO (l, m) >>=
\(l', lmin) ->
@horus
horus / gist:3838695
Created October 5, 2012 08:10
Coursera:progfun-2012, Week 3
This is an example of implementing set with binary tree, original Scala code:
abstract class IntSet {
def incl(x: Int): IntSet
def contains(x: Int): Boolean
def union(other: IntSet): IntSet
}
class Empty extends IntSet {
def contains(x: Int): Boolean = false
@horus
horus / gist:5683209
Last active December 17, 2015 22:39
import Control.Arrow ((&&&))
import Data.Bits (shiftR, (.&.), Bits(..))
import Data.Functor ((<$>))
import Data.List (intercalate)
import Data.Maybe (listToMaybe, fromMaybe)
import Network.BSD (getHostByName, HostEntry(..))
import System.Environment (getArgs)
main :: IO ()
main = do
import Control.Monad.State
half :: Int -> State [Int] Int
half x = do
xs <- get
put (x:xs)
return (x `div` 2)
main = print $ runState (half >=> half >=> half >=> half >=> half >=> half >=> half >=> half >=> half >=> half $ 1024) []
@horus
horus / gist:5821516
Created June 20, 2013 09:40
Build fontforge (20120731-b) on Mac OS X 10.8
XCODE_ROOT=`xcode-select -print-path`
SDK_ROOT=${XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
FRAMEWORK_ROOT=${SDK_ROOT}/System/Library/Frameworks
sed -i.bak -e 's|/Developer/Headers/FlatCarbon/Files.h|CarbonCore/Files.h|' fontforge/macbinary.c fontforge/startui.c gutils/giomime.c
sed -i.bak -e 's|/Developer/Headers/FlatCarbon/CarbonEvents.h|HIToolbox/CarbonEvents.h|' fontforge/startui.c
env CFLAGS="-isysroot ${SDK_ROOT} -F${FRAMEWORK_ROOT}/CoreServices.framework/Frameworks -F${FRAMEWORK_ROOT}/Carbon.framework/Frameworks" \
./configure --prefix=$HOME/local --with-freetype-src=$HOME/local/src/freetype-2.5.0.1 \
--enable-double --without-freetype-bytecode --without-python --with-static-imagelibs