Skip to content

Instantly share code, notes, and snippets.

@nebuta
nebuta / encode_test_coarse.rb
Created November 8, 2011 09:40
Test algorithm with smaller dictionaries
require 'rubygems'
require 'hpricot'
$asciilist = (0x20..0x7e).to_a | [0x09,0x0a,0x0c,0x0d]
def parse(lines)
arr = Array.new(65536)
start = 0
lines.each{|line|
@nebuta
nebuta / wikinotblock.user.js
Created January 18, 2012 05:55
Wikipedia blackout bypass
// ==UserScript==
// @name WikipediaNotBlock
// @version 1.0
// @namespace web2lab.web.fc2.com
// @description I support Wikipedia's opinion on SOPA, but let me access Wikipedia.
// @include http://en.wikipedia.org/*
// ==UserScript==
window.addEventListener('DOMNodeInserted',setcss);
@nebuta
nebuta / gist:2841750
Created May 31, 2012 07:58
Haskell unit calculation test
-- Haskell unit calc test
data (Num a) => Unit a = Unit a a a -- dimensions of meter, kilogram, and second
deriving (Eq)
instance (Num a)=>Show (Unit a) where
show (Unit m k s) = (f "kg" k) ++ " " ++ (f "m" m) ++ " " ++(f "s" s)
where
f s 0 = ""
f s 1 = s
@nebuta
nebuta / gist:2904427
Created June 10, 2012 07:54
HTML parser prototype
module ParseHtml where
import Text.ParserCombinators.Parsec
import Data.Char
import Data.Tree
import Data.List
import Test.QuickCheck
import Control.Monad
data Tag = Tag TagName [TagProp] [Content] | TagSingle TagNameSingle [TagProp] | TagScript [TagProp] String deriving (Eq,Show)
@nebuta
nebuta / gist:3064778
Created July 7, 2012 04:57
Text.Regex.Posix error
Prelude> :m + Text.Regex.Posix
Prelude Text.Regex.Posix> let pat = "(foo[a-z]*bar|quux)"
Prelude Text.Regex.Posix> "before foodiebar after" =~ pat :: (String,String,String)
<interactive>:4:26:
No instance for (RegexContext
Regex source10 (String, String, String))
arising from a use of `=~'
Possible fix:
add an instance declaration for
@nebuta
nebuta / gist:3095944
Created July 12, 2012 05:07
Hackage mirror error
Internal Server Error
Ran commands: withTmpDir rm -f /tmp/tmpThreadId84264430607 mkdir /tmp/tmpThreadId84264430607 pwd cd /tmp/tmpThreadId84264430607 writefile /tmp/tmpThreadId84264430607/tmp.hs cd /home/tanakh/hackage-mirror rm -rf /tmp/tmpThreadId84264430607 find /tmp/tmpThreadId84264430607 ls /tmp/tmpThreadId84264430607 Exception: /tmp/.haddock-30607: createDirectory: already exists (File exists)
Copyright (c) 2012, Hideyuki Tanaka
-- peggytest.hs
{-# Language TemplateHaskell, QuasiQuotes, FlexibleContexts #-}
module Nums (numsqq) where
import Text.Peggy
genParser [("numsqq", "nums")] [peggy|
nums :: [Int]
= num*
@nebuta
nebuta / tiff.hs
Created November 25, 2012 22:59
TIFF tag reader prototype
{-# LANGUAGE OverloadedStrings #-}
import Data.Attoparsec.ByteString as A
import Control.Applicative ((<|>))
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as LB
import System.IO
import Data.Maybe
import Data.String
@nebuta
nebuta / gist:4248429
Created December 10, 2012 04:47
Yesod 1.1.5 install log
Configuring SHA-1.6.1...
Building SHA-1.6.1...
Preprocessing library SHA-1.6.1...
[1 of 1] Compiling Data.Digest.Pure.SHA ( Data/Digest/Pure/SHA.hs, dist/build/Data/Digest/Pure/SHA.o )
[1 of 1] Compiling Data.Digest.Pure.SHA ( Data/Digest/Pure/SHA.hs, dist/build/Data/Digest/Pure/SHA.p_o )
In-place registering SHA-1.6.1...
Running Haddock for SHA-1.6.1...
Preprocessing library SHA-1.6.1...
Warning: The documentation for the following packages are not installed. No
links will be generated to these packages: rts-1.0
@nebuta
nebuta / code_benchmark.rb
Created December 16, 2012 11:24
Ruby scraping benchmark code
require 'rubygems'
require 'nokogiri'
require 'open-uri'
10.times do
doc = Nokogiri::HTML(open("http://www.w3.org/html/wg/drafts/html/master/single-page.html"))
puts(doc.css("ul > li").length.to_s + " elements.")
end