Skip to content

Instantly share code, notes, and snippets.

View takaki's full-sized avatar

TANIGUCHI Takaki takaki

View GitHub Profile
@takaki
takaki / cleanup.hs
Created October 3, 2012 04:10 — forked from Jxck/cleanup.hs
cleanup without .hs files
import System.Directory
import Data.List
forRemove :: (String, String) -> Bool
forRemove (_, ".") = False
forRemove (_, "..") = False
forRemove (_, ".hs") = False
forRemove (_, ".git") = False
forRemove ("cleanup", _) = False
forRemove _ = True
@takaki
takaki / gist:3825068
Created October 3, 2012 04:50
HXT, Text Node, Shift-JIS
import Codec.Binary.UTF8.String
import Codec.Text.IConv
import Data.List
import Text.XML.HXT.Core
import qualified Data.ByteString.Lazy as BSL
main = do
cs <- BSL.readFile "4731398C.html"
let u8s = convert "CP932" "UTF-8" cs
let html = decode (BSL.unpack u8s)
@takaki
takaki / gist:3826270
Created October 3, 2012 10:27
HTTPS connection with urllib2
#!/usr/bin/python
import urllib2
proxy_handler = urllib2.ProxyHandler({'https': 'http://localhost:8888/'})
opener = urllib2.build_opener(proxy_handler)
print opener.open("https://www.google.com/").read()
@takaki
takaki / gist:3832030
Created October 4, 2012 07:44
${HOME}/.config/font-manager/local.conf: It solves that Mincho is displayed in the Gothic font.
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<match target="pattern">
<test qual="any" name="family">
<string>Ryumin</string>
</test>
<edit name="family" mode="prepend" binding="strong">
<string>IPAMincho</string>
</edit>
@takaki
takaki / gist:3870297
Created October 11, 2012 05:07
simple example for parse gnucash xml by lxml
#!/usr/bin/python
from lxml import etree
import gzip
tree = etree.parse(gzip.open('personal.gnucash'))
root = tree.getroot()
for i in tree.xpath('//gnc:GncInvoice[invoice:id[text()="000003"]]',namespaces=root.nsmap):
print(i.tag)
@takaki
takaki / gist:3878095
Created October 12, 2012 08:40
python locale format
#!/usr/bin/python
import locale
locale.setlocale(locale.LC_ALL,'')
locale.format_string("%d円", 12345, True)
@takaki
takaki / gist:3891747
Created October 15, 2012 09:48
HXT, XPath
import Codec.Binary.UTF8.String
import Codec.Text.IConv
import Data.List
import Text.XML.HXT.Core
import qualified Data.ByteString.Lazy as BSL
import Text.XML.HXT.XPath.Arrows
-- 日本語
main = do
cs <- BSL.readFile "4731398C.html"
@takaki
takaki / gist:3903522
Created October 17, 2012 03:19
world Cup 2014 Asian Qualifiers Group B
import Control.Monad
import Data.List
import Data.Maybe
data Country = Japan | Jordan | Australia | Oman | Iraq deriving (Eq,Show)
countries = [Japan, Jordan , Australia, Oman, Iraq]
countryPriority :: Country -> Int
countryPriority x
@takaki
takaki / gist:3930537
Created October 22, 2012 09:14
simple lxml sample
#!/usr/bin/python
from lxml import etree
tree = etree.parse(open('database.xml'))
blogs = tree.xpath('//row[user_id=5]')
for b in blogs:
print b.find('blog_id').text
@takaki
takaki / gist:3957294
Created October 26, 2012 06:47
lxml, XPath, HTML
#!/usr/bin/python
from lxml import etree
tree = etree.HTML(open('a.html').read())
# //*[@id="companyTopData"]/div[2]/table/tbody/tr[1]/td
inv = tree.xpath('//*[@id="companyTopData"]/div[2]/table/tr[1]/td')
for i in inv:
print(i.text)