Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hideaki-t
hideaki-t / init.html
Last active December 27, 2015 03:29
to test adding entries into an array for a ng-repeat-ed element
<select class="ng-pristine ng-valid" ng-options="e.name for e in entries" ng-model="entry">
<option value="0" selected="selected">
default
</option>
</select>
import sys
try:
from PySide import QtCore
from PySide import QtGui
from PySide import QtWebKit
except:
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import QtWebKit
@hideaki-t
hideaki-t / CSVParser.java
Created July 9, 2013 05:13
regex based CSV parser in Java(without newline support)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CSVParser {
private static final Pattern p = Pattern.compile(",|[^,\"]+|\"(?:[^\"]|\"\")*\"");
public static List<String> parse(final String line, final int max) {
if (max == 0) {
@hideaki-t
hideaki-t / gist:5929887
Created July 4, 2013 19:51
find 4-byte UTF-8 characters
import itertools
for i, f in zip(itertools.count(1), open('lex.csv', 'rb')):
for j, g in zip(itertools.count(0), f):
if g >= 0b11110000:
print(i, f[j:j+4], f[j:j+4].decode('utf-8'))
@hideaki-t
hideaki-t / csv2tsv.py
Created July 4, 2013 17:53
convert CSV file to TSV file
from sys import argv, stdin, stdout
from csv import reader, writer
enc = argv[2] if len(argv) > 2 else "UTF-8"
inputf = open(argv[1], encoding=enc) if len(argv) > 1 else stdin
writer(stdout, lineterminator='\n', delimiter='\t').writerows(reader((x.strip('\r\n') for x in inputf)))
@hideaki-t
hideaki-t / enum_switch_case.py
Last active December 19, 2015 07:59
Switch/Case implementation using Enum
from enum import Enum
class Signal(Enum):
red = 1
yellow = 2
green = 3
def switch(e, **cases):
cls = e.__class__
@hideaki-t
hideaki-t / filteropml.py
Last active December 18, 2015 15:09
filter the OPML, which was imported to Feedeen, using its import notification mail.
# coding: utf-8
from __future__ import print_function
import sys
import xml.etree.ElementTree as ET
import urllib.request
import html
def remove_node(root, node):
title = html.escape(node.attrib['title'])
for parent in root.findall('.//outline[@title="{}"]/..'.format(title)):
@hideaki-t
hideaki-t / Python: mmap with native type
Created May 28, 2013 18:34
Python 3+ can handle native types in mmaped region with memoryview
{
"metadata": {
"name": "mmap with native type"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@hideaki-t
hideaki-t / demo.ipynb
Created September 1, 2012 05:11
whoosh demo(ipython notebook)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.