Skip to content

Instantly share code, notes, and snippets.

View ainame's full-sized avatar

Satoshi Namai ainame

View GitHub Profile
(defun newline-or-open-line ()
"newline-or-openline is a new command for merging C-m and C-o"
(interactive)
(let ((string-exists-before-cursor (string-match "[^\\\s\\\n\\\t]" (buffer-substring (point-at-bol) (point))))
(string-exists-after-cursor (string-match "[^\\\s\\\n\\\t]" (buffer-substring (point) (point-at-eol)))))
(cond ((or (eolp)
(not string-exists-after-cursor)
(and string-exists-before-cursor string-exists-after-cursor))
(progn (princ 1) (newline) (indent-according-to-mode)))
(t (progn (princ 2) (open-line 1) (indent-according-to-mode))))))
(defun newline-or-open-line ()
"newline-or-openline is a new command for merging C-m and C-o"
(interactive)
(cond ((or (eolp)
(not (string-match "[^\\\s\\\n\\\t]" (buffer-substring (point) (point-at-eol)))))
(progn (newline) (indent-according-to-mode)))
(t (progn (open-line 1) (indent-according-to-mode)))))
(define-key global-map (kbd "C-m") 'newline-or-open-line)
(defun newline-or-open-line ()
"newline-or-openline is a new command for merging C-m and C-o"
(interactive)
(cond ((or (eolp)
(not (string-match "[^\\\s\\\n]" (buffer-substring (point) (point-at-eol)))))
(progn (newline) (indent-according-to-mode)))
(t (progn (open-line 1) (indent-according-to-mode)))))
(define-key global-map (kbd "C-m") 'newline-or-open-line)
use strict;
use warnings;
use Plack::Test;
use HTTP::Request;
use Benchmark qw/timethis/;
my $app = sub { [200, [], ['Hello, World!']] };
test_psgi $app, sub {
my $cb = shift;
/Users/namai/workspace/prog/perl/bench:
total used in directory 0 available 9773356
drwxr-xr-x 2 namai staff 68 9 14 00:36 .
drwxr-xr-x 17 namai staff 578 9 14 00:36 ..
@ainame
ainame / pre-commit
Last active December 22, 2015 17:08
ある歴史(BASE_COMMIT)以降に新規追加されたファイルが150行を超えたときにcommitをしないための、決意のpre-commit hookを書きました。
#!/usr/bin/env perl
use strict;
use warnings;
use Perl::Metrics::Simple;
use constant {
EXIT_STATUS_SUCCESS => 0,
PERL_MODULE_FILENAME_PATTERN => qr/\.(pm|pl)$/,
LIMIT_LINES_OF_CODE => 150,
BASE_COMMIT => '9e732c2',
#!/usr/bin/env perl
use strict;
use warnings;
use Perl::Metrics::Simple;
use constant {
EXIT_STATUS_SUCCESS => 0,
PERL_MODULE_FILENAME_PATTERN => qr/\.(pm|pl)$/,
LIMIT_LINES_OF_CODE => 150,
};
@ainame
ainame / pre-commit.pl
Last active December 22, 2015 15:49
git pre-commit hook。このままだと150行超えてる既存ファイルがコミットできなくなるので、どっかの歴史以降に新規追加されたファイルかどうかをチェックする処理をあとで追加。 
#!/usr/bin/env perl
use strict;
use warnings;
use Perl::Metrics::Simple;
use constant {
EXIT_STATUS_SUCCESS => 0,
PERL_MODULE_FILENAME_PATTERN => qr/\.pm$/,
LIMIT_LINES_OF_CODE => 150,
};
class HogeScreen < PM::Screen
@default_name = "fuba"
def self.name_accsessor
@default_name
end
def on_init
@name = self.class.name_accessor
end
@ainame
ainame / gist:6211761
Last active December 20, 2015 23:19
imenuでsubtestのdescriptionをぶっこ抜く奴。subtest用のminorモード作ってもうちょっとよくしたい。
(defvar cperl-imenu-subtest-extract-description-regexp-pattern
"\\(\s*\\)subtest\s*?['|\"]\\(.*\\)['|\"].*=>.*$")
(defun cperl-imenu-subtest-imenu-create-index ()
(let (index)
(goto-char (point-min))
(while (re-search-forward
cperl-imenu-subtest-extract-description-regexp-pattern
(point-max) t)
(push (cons (concat