Skip to content

Instantly share code, notes, and snippets.

@tsurushuu
tsurushuu / gist:1240214
Created September 25, 2011 04:05
readFile catch test.
import System.IO (hPutStrLn, stderr)
import Control.Exception (catch, IOException, SomeException)
import Prelude hiding (catch)
readFileWithDefault :: FilePath -> String -> IO String
readFileWithDefault filepath defaultString =
catch
(readFile filepath)
(\e -> do
return (e::SomeException)
@tsurushuu
tsurushuu / gist:1240227
Created September 25, 2011 04:27
twitter query string encoding.
import Network.HTTP
import Codec.Binary.UTF8.String
queryString :: String
queryString = "ひとし+君"
queryRPP :: Int
queryRPP = 10
makeRequestUrl :: String
fromResult :: Result a -> Maybe a
fromResult (Ok k) = Just k
fromResult (Error e) = Nothing
maybeFromObj :: JSON a => String -> JSObject JSValue -> Maybe a
maybeFromObj k o = maybe (Nothing) (fromResult . readJSON) (lookup k (fromJSObject o))
module Main (main) where
import System.Environment (getArgs)
import System.Console.GetOpt
data SearchOptions
= Query String | Rpp Int | Lang String | OutputFile String
deriving (Show)
options :: [OptDescr SearchOptions]
@tsurushuu
tsurushuu / gist:1257473
Created October 2, 2011 13:51
Graph test
module Main where
import System.Cmd
import Data.Graph.Inductive
import Data.Graph.Inductive.Graphviz
import Data.Graph.Inductive.Example
myGraph :: Gr String ()
myGraph = mkGraph
module Main where
import System.Directory
import Control.Monad
import Data.List
import Text.Regex
import Text.Regex.Posix
recursiveFiles :: FilePath -> IO [FilePath]
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.Run "cmd.exe /c milk web", vbhide
module Main where
import System
import Data.List
import Control.Monad
separateDiffPatch :: String -> [String]
separateDiffPatch str = map unlines . map (head . filter patchEnd . inits) . (filter patchStart . tails) . lines $ str
where
patchStart (l0 : l1 : l2 : ls) = and [isPrefixOf "From " l0, isPrefixOf "From: " l1, isPrefixOf "Date: " l2]
@tsurushuu
tsurushuu / open_with.py
Created December 12, 2011 14:47
for Sublime Text 2
###########################
# windows only
###########################
#import sublime
import sublime_plugin
import os
import os.path
[
{ "caption": "-" },
{ "command": "open_with_default", "caption": "Open with Default App" },
{ "command": "cmd_window_here", "caption": "Command Window Here" },
{ "command": "bash_prompt_here", "caption": "Bash Prompt Here" },
{ "caption": "-", "id": "end" }
]