Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / mecab.reading.py
Created May 20, 2013 21:11
Example using reading.mecab from Anki
# -*- coding: utf-8 -*-
from reading import mecab
from codecs import open
print mecab.reading(u'もう 冗談言わないでよ').encode('utf8')
@ispedals
ispedals / youtube-video-explorer.pl
Created May 20, 2013 21:05
Mojolicious::Lite app that explores a youtube video by both displaying both the author's video and related videos recursively
#perl
use v5.16;
use warnings;
use XML::Smart;
use Mojolicious::Lite;
my %videos; #videos to be saved; structured <id:[title, author_url, id, duration, [thumbnails]]>
my %seen; #videos that have been seen and either saved or rejected; keys are video ids
my %authors; #authors whose uploads have been seen; keys are author urls
@ispedals
ispedals / test-xml.pl
Created May 20, 2013 20:53
Compare performance of Mojo::DOM and XML::Smart
#!perl
use v5.16;
use utf8;
use XML::Smart;
use Mojo::DOM;
use Benchmark qw( timethese cmpthese );
my $xml = <<'EOF';
<?xml version='1.0' encoding='UTF-8'?><feed gd:etag="W/&quot;A0ACRHgyfyp7I2A9WhNQGUo.&quot;" xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:gd="http://schemas.google.com/g/2005" xmlns:media="http://search.yahoo.com/mrss/" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:yt="http://gdata.youtube.com/schemas/2007"><id>tag:youtube.com,2008:user:chemicalsreact14:uploads</id><updated>2012-11-27T01:29:25.697Z</updated><category scheme="http://schemas.google.com/g/2005#kind" term="http://gdata.youtube.com/schemas/2007#video" /><title>Uploads by chemicalsreact14</title><logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link href="http://gdata.youtube.com/feeds/api/users/chemicalsreact14?v=2" rel="related" type="application/atom+xml" /><link href="http://www.youtube.com/channel/UC6PnMX0ZSS4hnqGRmByH4gA/videos" rel="alternate" type="text/ht
@ispedals
ispedals / server.py
Created May 20, 2013 20:48
Example using BaseHTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from urllib import unquote
b=[]
class MyHandler(BaseHTTPRequestHandler):
def do_GET(self):
if not self.path in b:
f.write('<li><a href=%s>%s</a></li>\r\n'%(unquote(self.path)[1:],unquote(self.path)[1:]))
b.append(self.path)
print self.path
@ispedals
ispedals / filepicker.js
Created May 20, 2013 20:46
Example addon showing how to call the filepicker on Firefox for Android
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
function log(str) { Services.console.logStringMessage(str); }
function showToast(aWindow, message) { aWindow.NativeWindow.toast.show(message, "short"); }
var g;
@ispedals
ispedals / gist:5614958
Created May 20, 2013 19:51
youtube-dl.py command for downloading videos with output templating
python youtube-dl.py -v -f 18 -o "/Users/Owner/desktop/d/%(uploader)s/%(id)s_%(upload_date)s"