Skip to content

Instantly share code, notes, and snippets.

@miau
miau / emphasize_distortion.py
Created May 12, 2014 16:08
Scripts to research ScanSnap/fi7160
import Image
import glob
import os.path
for infile in glob.glob("*.jpg"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
pixels = im.load()
(w, h) = im.size
for y in range(h):
@miau
miau / make_raw_files.py
Created May 6, 2014 15:24
Scripts to research ScanSnap
import Image
import ImageDraw
import shutil
import tempfile
import os
img = Image.new('RGB', (5224, 5224), (220, 230, 232))
dr = ImageDraw.Draw(img)
dr.rectangle(((1000, 1000), (4999, 4999)), (255, 255, 255), (255, 255, 255))
dr.rectangle(((1010, 1010), (1019, 1019)), (255, 0, 0), (255, 0, 0))
@miau
miau / tic.pl
Created May 12, 2013 14:43
Google Code Jam 2013 - Qualification Round - Problem A. Tic-Tac-Toe-Tomek
use 5.012;
use warnings;
<>;
$/ = '';
my $c;
while (<>) {
print 'Case #' . ++$c . ': ';
s/\s+/ /g;
if (/[OT]{4}|[OT](?:...[OT]){3}|[OT](?:....[OT]){3}|[OT](?:.....[OT]){3}/) {
diff --git a/lib/watobo/core/session.rb b/lib/watobo/core/session.rb
index c7c1eeb..037a2ed 100644
--- a/lib/watobo/core/session.rb
+++ b/lib/watobo/core/session.rb
@@ -19,6 +19,7 @@
# along with WATOBO; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# .
+@@user_id = 1
module Watobo
@miau
miau / zend_alloc.patch
Created November 4, 2012 13:48
patch for Windows PHP to analyze memory allocation
--- zend_alloc.c.org Wed Oct 17 18:21:42 2012
+++ zend_alloc.c Sun Nov 04 22:56:22 2012
@@ -263,17 +263,29 @@
static zend_mm_segment* zend_mm_mem_win32_alloc(zend_mm_storage *storage, size_t size)
{
- return (zend_mm_segment*) HeapAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, size);
+ zend_mm_segment* segment;
+
+ segment = (zend_mm_segment*) HeapAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, size);
@miau
miau / Jp.php
Created November 3, 2012 18:07
A PHP script to reproduce segfault on apc_request_shutdown()
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
@miau
miau / gitk_show_svn_rev.patch
Created February 10, 2012 16:05
a patch for gitk to show git-svn-ids on headlines
--- gitk.org Mon Jan 16 01:08:02 2012
+++ gitk Fri Feb 10 18:23:31 2012
@@ -1676,6 +1676,10 @@
if {$i >= 0} {
set headline [string trimright [string range $headline 0 $i]]
}
+ set svnrev [lindex [regexp -linestop -inline {git-svn-id:.*@([[:digit:]]+)} $comment] 1]
+ if {$svnrev != {}} {
+ set headline "\[$svnrev\] $headline"
+ }
@miau
miau / bench.log
Created December 12, 2011 13:48
benchmark of PHP stable sort
overhead(shuffled ): 0.0017560 2420,3297,5637,1083,5790
overhead(duplicated): 0.0017490 622,4325,1760,1691,4110
overhead(sorted ): 0.0005720 1,2,3,4,5
mergesort(shuffled ): 0.9389420 1,10,100,1000,10000
mergesort(duplicated): 0.9406991 1,1,10,10,100
mergesort(sorted ): 0.3923521 1,10,100,1000,10000
schwartzian_transform(shuffled ): 0.6981239 1,10,100,1000,10000
schwartzian_transform(duplicated): 0.6524200 1,1,10,10,100
schwartzian_transform(sorted ): 0.6394210 1,10,100,1000,10000
schwartzian_transform2(shuffled ): 0.6490870 1,10,100,1000,10000
@miau
miau / bench.log
Created October 27, 2011 18:40
benchmark of creating PHP DateTime with microseconds
(overhead): 0.012856006622314
gettimeofday+list: 0.79171109199524
gettimeofday: 0.78512001037598
gettimeofday2: 0.77574801445007
trim: 0.62337398529053
substr: 0.63026404380798
substr+createFromFormat: 0.60127902030945
float: 0.59996008872986
float2: 0.60790085792542
float3: 0.60153198242188