Skip to content

Instantly share code, notes, and snippets.

@ispedals
ispedals / mecab.reading.json.server.py
Created May 20, 2013 21:12
Example wrapping reading.mecab from Anki with a JSON web interface
# -*- coding: utf-8 -*-
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from urlparse import urlparse
from reading import mecab
import json, urllib
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
expr = u"カリン、自分でまいた種は自分で刈り取れ"
@ispedals
ispedals / google-code-downloader.pl
Created May 20, 2013 21:27
Downloads the files in a google code svn directory by scraping the web interface
#!perl
use v5.12;
use strict;
use warnings;
use WWW::Mechanize;
use Cwd;
my $mech = WWW::Mechanize->new( autocheck => 1 );
my $desktop= "Desktop";
@ispedals
ispedals / DirectoryTraverser.pm
Created May 20, 2013 21:28
DirectoryTraverser interace inspired by Higher Order Perl
#!perl
package DirectoryTraverser;
use strict;
use warnings;
sub new()
{
my $class = shift;
my $self = {
@ispedals
ispedals / findWordsWithSameKanjiandReading.py
Created May 20, 2013 21:43
Find words with the same kanji and reading
# -*- coding: utf-8 -*-
import sqlite3
import re
#or another Rikaichan formatted dictionary file
d='.anki\\plugins\\yomichan_plugin\\languages\\japanese\\data\\dict.sqlite'
f=sqlite3.connect(d).cursor()
lookups=[(u'とく', u'徳')]
def findWordsWithSameKanjiandReading(kana, kanji):
@ispedals
ispedals / gist:5615827
Created May 20, 2013 21:44
Converts the currently set .ass subtitle to .srt and sets it as the subtitle for the current video in XBMC for Xbox
"""
ass2srt.py
Converts the currently set .ass subtitle to .srt and sets it as the subtitle for the current video
"""
import re
import xbmc
from os.path import basename, splitext
from datetime import time
import traceback
import codecs
@ispedals
ispedals / ftppicker.py
Created May 20, 2013 21:45
Recursivly traverses a FTP directory, picking a random user-given number of files and outputting them in the format {image: http://<filename>}
"""
Recursivly traverses a FTP directory, picking a random user-given number of files and outputting them in the format
{image: http://<filename>}
"""
import ftplib
import random
from optparse import OptionParser
def traverse(ftp, depth=0):
"""
@ispedals
ispedals / ftpproxy.py
Created May 20, 2013 21:46
A HTTP server that proxies GET requests to a FTP server
"""
A HTTP server that proxies GET requests to a FTP server
"""
import ftplib
from mimetypes import guess_type
import BaseHTTPServer
from urllib2 import unquote
from optparse import OptionParser
@ispedals
ispedals / charname.pl
Created May 20, 2013 21:49
Display the character name of farsi letters in a sentence
#!perl
use v5.12;
use strict;
use warnings;
use utf8;
use Unicode::UCD 'charinfo';
my $SENTENCE = '';
@ispedals
ispedals / copysubs.py
Created May 20, 2013 21:50
Copies the currently playing subtitle in XBMC for Xbox
import xbmc
import shutil
ass_subtitle='special://temp/%s' % xbmc.Player().getSubtitles()
shutil.copy(ass_subtitle, 'Q:\\scripts\\')
@ispedals
ispedals / dailymotionresolver.py
Created May 20, 2013 21:51
Resolves dailymotion video urls
import urllib2
import re
uid='xv3f6f'
f = urllib2.urlopen('http://www.dailymotion.com/embed/video/%s' % uid).read()
url=re.findall('"stream_h264_url":"(.*?)",', f, re.DOTALL)
resolved_url=url[0].replace('\\','')
print resolved_url