This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
unsigned int sharedPrefixLength(const char *a, const char *b); | |
std::string longestRepeatedString(const std::string s); | |
int main() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.DList as DL | |
import Control.Monad (forever) | |
base62Encode :: Integer -> String | |
base62Encode = map ((base62Alphabet!!) . fromIntegral) . DL.toList . digits | |
where base62Alphabet = ['0'..'9'] ++ ['A'..'Z'] ++ ['a'..'z'] | |
digits n | n < 62 = DL.singleton n | |
| otherwise = digits (n `div` 62) `DL.snoc` (n `mod` 62) | |
readUuid :: String -> Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE LambdaCase #-} | |
import Graphics.HsExif (parseFileExif, getGpsLatitudeLongitude) | |
import System.Environment (getArgs) | |
import System.FilePath (takeFileName) | |
import System.IO (hPutStrLn, stderr) | |
import Data.List (intercalate) | |
printGeoLine :: FilePath -> IO () | |
printGeoLine filename = do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compile with: gcc -Wall -ansi -pedantic getbg.c -o getbg -lX11 -ljpeg | |
// usage: ./getbg mybg.jpg | |
#include <X11/Xlib.h> | |
#include <X11/Xatom.h> | |
#include <X11/Xutil.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <jpeglib.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
URL=http://www.yr.no/sted/Norge/Sør-Trøndelag/Trondheim/Trondheim/varsel.xml | |
TEMP=$(wget -q -O - $URL | awk -F\" '/<temperature/ {print $4;exit}') | |
if [ $TEMP -gt "20" ]; then | |
echo "<fc=#ee4444>${TEMP}</fc>" | |
elif [ $TEMP -lt "0" ]; then | |
echo "<fc=#3bb9ff>${TEMP}</fc>" | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GEOIP_API_KEY="" # http://geoio.com/signup.php | |
WEATHER_API_KEY="" # http://www.worldweatheronline.com/register.aspx | |
IP=$(curl -s "http://whatismyip.org/") | |
GEOIP_URL="http://api.geoio.com/q.php?key=$GEOIP_API_KEY&qt=geoip&d=comma&q=$IP" | |
LAT_LONG=$(curl -s "$GEOIP_URL"|awk -F, '{print $(NF-1)","$NF}') | |
WEATHER_URL="http://www.worldweatheronline.com/feed/weather.ashx?q=${LAT_LONG}&format=csv&num_of_days=2&key=$WEATHER_API_KEY" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char (ord, chr) | |
import Data.List (elemIndex) | |
import Data.Maybe (fromJust) | |
import Control.Arrow | |
data Card a = Card a | JokerA | JokerB deriving (Show, Eq) | |
type Deck = [Card Int] | |
-- we start with a deck in bridge order | |
startDeck :: Deck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- lazily produce the binary representation of a number as a list of [0,1] | |
bin ∷ Integer → [Integer] | |
bin n = bin' n ((floor ∘ logBase 2 ∘ fromIntegral) n) | |
where bin' 1 0 = [1] | |
bin' 0 0 = [0] | |
bin' a b = if a ≥ 2^b | |
then 1:bin' (a-2^b) (b-1) | |
else 0:bin' a (b-1) | |
popCount :: Integer -> Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# Language FlexibleContexts #-} | |
import Data.Packed.Matrix | |
import Numeric.Container | |
normalize :: (Container Vector e) => Matrix e -> Matrix e | |
normalize m = let scaleFactor = sumElements m | |
in (fromLists . map (map (/scaleFactor)) . toLists) m | |
forward :: (Product e, Container Vector e) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// by alex evans, 2011. released into the public domain. | |
// based on a first ever reading of the png spec, it occurs to me that a minimal png encoder should be quite simple. | |
// this is a first stab - may be buggy! the only external dependency is zlib and some basic typedefs (u32, u8) | |
// | |
// more context at http://altdevblogaday.org/2011/04/06/a-smaller-jpg-encoder/. | |
// | |
// follow me on twitter @mmalex http://twitter.com/mmalex | |
// | |
u32 crc_table[256]={0}; | |
void make_crc_table(void) |
OlderNewer