Skip to content

Instantly share code, notes, and snippets.

@kuwa72
kuwa72 / lg.zsh
Created March 31, 2017 03:46
Life game(requirements: zsh, egzact. Tested on OSX).
#!/usr/bin/env zsh
FO=$(cat)
X=$(head -n 1 <<<$FO)
YL=$(echo $FO|wc -l|bc)
FF=$((echo $X|tr 1 0;echo $FO;echo $X|tr 1 0)|addl 0\ |addr \ 0)
for L in {1..$YL};do
for C in {1..$(echo $X|awk '{print NF}')}; do
echo $FF | sed -n $L,$((L+2))p | cut -d \ -f $C,$((C+1)),$((C+2)) | xargs | {
read B
if echo $B | grep -q '. . . . 1 . . . .';then
@kuwa72
kuwa72 / 27-q1.sh
Last active February 15, 2017 05:12
Emacsシェル芸サンプル(27回Q1)https://blog.ueda.asia/?p=9309
echo abcdefghijklmn | emacs -Q --batch --insert /dev/stdin --eval '(progn (while (re-search-forward "\\(.\\)\\(.\\)" nil t) (replace-match (concat "\\1" (capitalize (match-string 2))) nil nil))(princ (buffer-string)))'
@kuwa72
kuwa72 / 27-q6.sh
Created February 15, 2017 05:11
Emacsシェル芸サンプル(27回Q6) https://blog.ueda.asia/?p=9309
echo 1 | emacs -Q --batch --insert /dev/stdin --eval '(let ((bs (substring (buffer-string) 0 1))) (defun x (i s) (if (< i 10) (progn (princ (concat s "\n"))(x (+ i 1) (concat s bs))))) (x 0 bs) )'
@kuwa72
kuwa72 / Q4.php
Created December 25, 2016 09:15
シェル芸勉強会 24回 Q4
<?php
require_once 'vendor/autoload.php';
use \PhpOffice\PhpPresentation\IOFactory;
\PhpOffice\PhpPresentation\Autoloader::register();
$oWriter = IOFactory::createReader('PowerPoint2007');
$prst = $oWriter->load(__DIR__ . '/20141019OSC_LT.pptx');
@kuwa72
kuwa72 / iobench.php
Created March 14, 2016 14:37
Tiny IO benchmark in PHP.
<?php
for ($j = 0; $j < 100; $j++) {
$time = microtime(true);
for ($i = 0; $i < 1000; $i++) {
$fn = sprintf("%04d", $i);
file_put_contents($fn . ".spf", "asdfasdfasdfasdf");
}
echo (microtime(true) - $time);
echo ",";
@kuwa72
kuwa72 / redminerestInterface.class.php.diff
Created April 24, 2013 10:50
TestLink 1.9.6 and Redmine2 interface patch(for Japanese). Fixed call htmlentities with character encoding for broked multibyte chars. Fix Issues url path.
diff -ru tm//lib/issuetrackerintegration/redminerestInterface.class.php /var/www/tm/lib/issue[0/494]integration/redminerestInterface.class.php
--- tm//lib/issuetrackerintegration/redminerestInterface.class.php 2013-03-10 02:20:54.000000000 +0900
+++ /var/www/tm/lib/issuetrackerintegration/redminerestInterface.class.php 2013-04-24 19:13:06.622029202 +0900
@@ -55,7 +55,7 @@
$base = trim($this-&gt;cfg-&gt;uribase,&quot;/&quot;) . '/'; // be sure no double // at end
if( !property_exists($this-&gt;cfg,'uriview') )
{
- $this-&gt;cfg-&gt;uriview = $base . 'issues/show/';
+ $this-&gt;cfg-&gt;uriview = $base . 'issues/';
}
@kuwa72
kuwa72 / gist:5381320
Created April 14, 2013 03:33
Posgres driver fix 'fetch_version' and 'pg_error' for CodeIgniter 2.1.3
161c161,164
< return "SELECT version() AS ver";
---
> $version = @pg_fetch_array(@pg_query($this->conn_id, "SELECT version() AS ver"));
> $version_array = explode(" ", $version['ver']);
> $version_array['server'] = $version_array[1];
> return $version_array;
700a704,706
> function pg_error() {
> pg_last_error();
@kuwa72
kuwa72 / gist:5381197
Last active December 16, 2015 04:59
Patch of pached CIUnit(https://bitbucket.org/kenjis/my-ciunit).
diff -ur ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/config/config.php src/application/third_party/CIUnit/config/config.php
--- ../../temp/kenjis-my-ciunit-27a0665997a8/application/third_party/CIUnit/config/config.php 2012-01-18 01:27:00.000000000 +0900
+++ src/application/third_party/CIUnit/config/config.php 2013-04-03 17:56:13.738279800 +0900
@@ -8,6 +8,8 @@
*/
$config['ciu_subclass_prefix'] = 'CIU_';
+$config['log_threshold'] = 4;
+$config['log_path'] = 'logs/';
@kuwa72
kuwa72 / scrape.scm
Created February 20, 2013 07:08
Gauche CGI, Scrape site-titles in LAN nodes with threads. LAN内で動いているWebサイトからTitleを抜いてリンク集にするCGIです。 マルチスレッドのおかげで概ね高速に動作しますが、Cygwinのpthreadでは情報が抜ける場合が多いです。
#!/Gauche/bin/gosh
(use text.html-lite)
(use rfc.http)
(use rfc.uri)
(use www.cgi)
(use sxml.ssax)
(use sxml.sxpath)
(load "htmlprag.scm")
(use srfi-27) ; random-integer
@kuwa72
kuwa72 / scrape.pl
Created February 20, 2013 07:02
CGI, Scrape site-titles in LAN nodes with threads. **Caution! Its SEGV on win32 perl.** LAN内で動いているWebサイトからTitleを抜いてリンク集にするCGIです。 マルチスレッドのおかげで高速に動作しますが、Win32のPerlは異常終了するようです。
#!"C:\xampp\perl\bin\perl.exe"
print "Content-type: text/html\n\n";
use strict;
use warnings;
use threads;
use threads::shared;
use Thread::Semaphore;