Skip to content

Instantly share code, notes, and snippets.

@syohex
syohex / cperl-imenu.el
Created November 8, 2012 09:25
my own perl imenu. Default imenu provides too many information for me
(defun my/cperl-imenu-create-index ()
(let (index)
;; collect subroutine
(goto-char (point-min))
(while (re-search-forward "^\\s-*sub\\s-+\\([^ ]+\\)" nil t)
(push (cons (format "Function: %s" (match-string 1))
(match-beginning 1)) index))
;; collect subtest
(goto-char (point-min))
@syohex
syohex / swap-buffer.el
Created November 13, 2012 00:47
swap buffer between 2 windows
(defun swap-buffers ()
(interactive)
(let ((curwin (selected-window))
(curbuf (window-buffer)))
(other-window 1)
(set-window-buffer curwin (window-buffer))
(set-window-buffer (selected-window) curbuf)))
(define-key my/ctrl-q-map (kbd "b") 'swap-buffers)
@syohex
syohex / compass.pl
Created November 13, 2012 14:19
Samples of Graphviz::Gviz
#!/usr/bin/env perl
use strict;
use warnings;
use lib qw(../lib);
use Graphviz::DSL;
my $graph = graph {
route 'a:n' => 'b:s';
route 'a:w' => 'b:w';
@syohex
syohex / prototype.pl
Created November 14, 2012 13:24
Perl prototype is too difficult to understand
#!/usr/bin/env perl
use strict;
use warnings;
sub with_prototype ($) {
print "@_\n";
}
with_prototype(()); # OK, pass undef
with_prototype(("a", "b")); # OK, pass 'b', ignore 'a'
@syohex
syohex / eratosthenes.py
Created November 15, 2012 00:39
Sieve of Eratosthenes
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
def eratos(n):
nums = dict([(x, 1) for x in range(2, n)])
for x in range(2, n):
i = 2
@syohex
syohex / merge_soft.py
Created November 15, 2012 01:54
Merge sort implementation in Python
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import random
def merge_sort(nums):
if len(nums) <= 1:
return nums
else:
b, c = split(nums)
@syohex
syohex / when.pl
Created November 15, 2012 03:52
Port of when.rb
package Promise;
use strict;
use warnings;
sub new {
my ($class, $deferred) = @_;
bless {
deferred => $deferred,
}, $class;
@syohex
syohex / support-haskell.el
Created November 16, 2012 07:09
popup error message with flymake at current line
(defun flymake-display-err-menu-for-current-line ()
(interactive)
(let* ((line (flymake-current-line-no))
(line-err-info (flymake-find-err-info flymake-err-info line))
(error-infos (nth 0 line-err-info))
(eof-char (char-to-string 0)))
(when error-infos
(loop for error-info in error-infos
for message = (flymake-ler-text error-info)
for file = (flymake-ler-file error-info)
@syohex
syohex / direx-chmod.patch
Created November 16, 2012 14:50
Support chmod in direx.el
diff --git a/direx.el b/direx.el
index 2026806..ffd48df 100644
--- a/direx.el
+++ b/direx.el
@@ -440,6 +440,7 @@ mouse-2: find this node in other window"))
(define-key map (kbd "C") 'direx:do-copy-files)
(define-key map (kbd "D") 'direx:do-delete-files)
(define-key map (kbd "+") 'direx:create-directory)
+ (define-key map (kbd "M") 'direx:do-chmod-file)
map))
@syohex
syohex / like-vim.el
Created November 19, 2012 13:37
vim binding in elisp(Ctrl-z = Vim's ESC)
;;;; Like Vim
;; 'C-z prefix'
(defvar ctrl-z-map (if (featurep 'elscreen)
elscreen-map
(make-sparse-keymap)))
(defalias 'ctrl-z-prefix ctrl-z-map)
(define-key global-map (kbd "C-z") 'ctrl-z-prefix)
;; Deletion('C-z d' prefix)