Skip to content

Instantly share code, notes, and snippets.

View mumumu's full-sized avatar

Yoshinari Takaoka mumumu

View GitHub Profile
#!/usr/bin/env python
import redis
from optparse import OptionParser
from benchmarker import Benchmarker
parser = OptionParser()
parser.add_option("-n", "--num", dest="num", action="store",
help="iterate number", type="int", default=10000)
@mumumu
mumumu / sqlalchemy_snippet.py
Created January 7, 2014 11:13
sqlalchemy snippet.
#!/usr/bin/env python
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///:memory:', echo=True)
Session = sessionmaker(bind=engine)
Base = declarative_base()
#!/usr/bin/env python
from fabric.api import local, sudo, hosts, env
env.warn_only = True
env.skip_bad_hosts = True
def localup():
local('sudo apt-get update && sudo apt-get upgrade')
@mumumu
mumumu / phpdoc_rev_compare.py
Last active December 19, 2015 00:39
php ドキュメントのリポジトリのうち、マスタとなる en と 日本語 の ja を比較し、非常におおまかな差分情報を出力するPythonスクリプト。細かい fuzzy 度合いはわからないので注意。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
phpdoc_rev_compare.py
Description:
php ドキュメントのリポジトリのうち、マスタとなる
en と 日本語 の ja を比較し、以下の情報を出力する
@mumumu
mumumu / ImageRotateUtil.java
Last active April 8, 2022 11:03
Automatically corrects the orientation of image by interpreting exif:Orientation value. This class depends on JMagick and apache-sanselan.
package org.mumumu.test;
import java.io.ByteArrayOutputStream;
import magick.ImageInfo;
import magick.MagickImage;
import org.apache.sanselan.Sanselan;
import org.apache.sanselan.common.IImageMetadata;
import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
@mumumu
mumumu / addTargetBlankattrToAnchor.js
Last active January 25, 2019 10:47
ページ内 a タグを target="_blank" に変えるブックマークレット。今時の # な URL だったら意味無いけどね。
javascript:var elms=document.getElementsByTagName('a');for(var i=0;i<elms.length;i++){elms[i].setAttribute('target','_blank');}
@mumumu
mumumu / difference_of_keyword_args.txt
Last active December 16, 2015 16:49
difference of keyword arguments between Ruby 2.0.0 and Python.
mumumu@www 17:12:11$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def test(a = []):
... a.append(10)
... print a
...
>>> test()
[10]
@mumumu
mumumu / Smarty2.6.26_to_2.6.27.patch
Created March 10, 2013 13:16
Smarty 2.6.26 to 2.6.27 change by possible XSS
Index: ChangeLog
===================================================================
--- ChangeLog (リビジョン 3764)
+++ ChangeLog (リビジョン 4660)
@@ -1,3 +1,8 @@
+2012-09-24 Uwe Tews
+
+ * Fixed escape Smarty error messages to avoid possible script execution
+
+
@mumumu
mumumu / stripInvalidXMLChars.java
Created February 21, 2013 08:26
jdom claims "....." is not legal for a JDOM character content: 0x... is not a legal XML character. for workaround, i used the following method. From http://blog.mark-mclaren.info/2007/02/invalid-xml-characters-when-valid-utf8_5873.html
/**
* This method ensures that the output String has only
* valid XML unicode characters as specified by the
* XML 1.0 standard. For reference, please see
* <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">the
* standard</a>. This method will return an empty
* String if the input is null or empty.
*
* @param in The String whose non-valid characters we want to remove.
* @return The in String, stripped of non-valid characters.
@mumumu
mumumu / tcp_client.pl
Created December 24, 2012 10:52
tcp client by perl, using low-level socket API.
#!/usr/bin/perl -w
use strict;
use warnings;
use IO::Socket;
use Data::Dumper;
my $socket = IO::Socket::INET->new(
Proto => 'tcp',
Type => SOCK_STREAM