Skip to content

Instantly share code, notes, and snippets.

@syohex
syohex / output.log
Created January 10, 2012 15:39
sample of el-test-more
syohei@gretsch:% prove -v --exec='emacs -Q --script' sample.el
sample.el ..
1..3
ok 1 - string type test
ok 2 - add test
ok 3 - matching test test
ok
All tests successful.
Files=1, Tests=3, 0 wallclock secs ( 0.01 usr 0.00 sys + 0.04 cusr 0.00 csys = 0.05 CPU)
Result: PASS
@syohex
syohex / simple_request.js
Created January 15, 2012 13:33
Simple download with node.js
var request = require('request');
var fs = require('fs');
var downloadUrl = process.argv[2];
if (typeof donwloadUrl === undefined) {
console.log("Usage: request.js URL");
process.exit(1);
}
request.get({ uri: downloadUrl }, function (error, response, body) {
@syohex
syohex / client.py
Created January 18, 2012 14:05
Simple Python http client
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
from http import Client, Request
url = ''
if len(sys.argv) > 1:
@syohex
syohex / dict.pl
Created January 23, 2012 02:31
Search english word meaning from Eijiro with Perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode;
use Term::ANSIColor qw(:constants);
use File::Which qw(which);
@syohex
syohex / Lisp.pm
Created January 29, 2012 08:54
Lisp in 45 lines of Perl
package Lisp;
use strict;
use warnings;
use Scalar::Util qw/looks_like_number/;
use List::MoreUtils qw/zip/;
sub new {
my $env; $env = {
':label' => sub { my ($name, $val) = @_ ; $env->{$name} = $val;},
':quote' => sub { $_[0] },
@syohex
syohex / konoha.el
Created February 17, 2012 06:39
flymake setting of konoha-mode
(require 'konoha-mode)
;; setting for flymake
(require 'flymake)
(add-to-list 'flymake-allowed-file-name-masks '("\\.k\\'" flymake-konoha-init))
(defun flymake-konoha-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
@syohex
syohex / zshrc
Created February 20, 2012 09:45
display stash number if stash >= 1
## show git branch at right prompt
autoload -Uz vcs_info
zstyle ':vcs_info:*' formats '[%b]'
zstyle ':vcs_info:*' actionformats '(%s)-[%b|%a]'
precmd () {
psvar=()
LANG=en_US.UTF-8 vcs_info
[[ -n "$vcs_info_msg_0_" ]] && psvar[1]="$vcs_info_msg_0_"
topdir=`git rev-parse --show-toplevel 2>/dev/null`
@syohex
syohex / resolution_osx.el
Created February 28, 2012 14:33
Get screen resolution on Mac OSX
(with-temp-buffer
(shell-command
"osascript -e 'tell application \"Finder\" to get bounds of window of desktop'" t)
(goto-char (point-min))
(if (re-search-forward "[0-9]+, [0-9]+, \\([0-9]+\\), \\([0-9]+\\)")
(let ((width (buffer-substring-no-properties
(match-beginning 1) (match-end 1)))
(height (buffer-substring-no-properties
(match-beginning 2) (match-end 2))))
(mapcar #'string-to-int (list width height)))))
@syohex
syohex / each_with_index.pl
Created March 6, 2012 02:01
Implementation of each_with_index in Perl
#!perl
use strict;
use warnings;
sub each_with_index (\@) {
my $array_ref = shift;
my $length = scalar @{$array_ref};
my $index = 0;
@syohex
syohex / insert_perl_module.el
Created March 7, 2012 02:04
Insert use statement
;; insert 'use Module' which is at cursor.
(define-key cperl-mode-map (kbd "C-c C-m") 'cperl-insert-use-statement)
(defun cperl-insert-use-statement ()
"use statement auto-insertion."
(interactive)
(let ((module-name (cperl-word-at-point))
(insert-point (cperl-detect-insert-point)))
(save-excursion
(let ((use-statement (concat "\nuse " module-name ";")))