Skip to content

Instantly share code, notes, and snippets.

@kobapan
kobapan / os-open-file.el
Created June 1, 2016 11:40
【emacs】指定した拡張子のファイルをOSで関連づけられたプログラムで開く
;; OS で直接開きたいファイルかどうかを判定する
(defun os-open-file-p (file)
(if (file-regular-p file)
(let ((ext (file-name-extension file))
;; OS で起動したいファイルの拡張子一覧
(os-open-file-suffixes '("doc" "docx"
"xls" "xlsx"
"ppt" "pptx"
"mdb" "mdbx"
"vsd" "vdx" "vsdx"
@kobapan
kobapan / tag_aware_previous_next_generator.rb
Last active May 10, 2016 11:35 — forked from stravid/category_aware_next_generator.rb
Tag aware previous next attribute for a Jekyll post
#how to use in template
#
#{{ page.tag }}'s post'
#<a href="{{site.url}}{{ page.tag_previous.url }}">&laquo; {{ page.tag_previous.title }}</a>
#<a href="{{site.url}}{{ page.tag_next.url }}">{{ page.tag_next.title }} &raquo;</a>
#
module Jekyll
class TagAwarePreviousNextGenerator < Generator
safe true
@kobapan
kobapan / date-mod-second.scm
Last active October 1, 2018 03:57
scheme で 日付を加減算。明日の日付とか、1週間後の日付とか。
;; @original [日付に対する加算 | 逆引きScheme](http://tips.cddddr.org/scheme/index.cgi?%e6%97%a5%e4%bb%98%e3%81%ab%e5%af%be%e3%81%99%e3%82%8b%e5%8a%a0%e7%ae%97)
(use srfi-19)
;; 日付 date の seconds 秒後の日付を返す。閏秒は考えない。
(define (date-mod-second date seconds)
(time-utc->date
(add-duration (date->time-utc date)
(make-time time-duration 0 seconds))))
@kobapan
kobapan / set-env-from-shell.el
Last active October 5, 2020 05:26
シェル の PATH と alias を、emacs に引き継ぐ
(defun set-env-from-shell ()
"シェル の PATH と alias を、emacs に引き継ぐ"
(let* ((trim (lambda (string &optional needle)
(let* ((n (if needle needle "[ \t\n\r]+"))
(s (if (string-match (concat "\\`" n) string)
(replace-match "" t t string)
string)))
(if (string-match (concat n "+\\'") s)
(replace-match "" t t s)
s))))
@kobapan
kobapan / trim.el
Last active October 11, 2017 08:30
文字列の先頭及び末尾から空白(又は指定文字)を取り除く emacs lisp
(defun trim (string &optional needle)
"Remove needle at the beginning and endding of string."
(let ((n (if needle needle "[ \t\n\r]+"))
(s (if (string-match (concat "\\`" n) string) ; "\`" バッファや文字列の先頭
(replace-match "" t t string)
string)))
(if (string-match (concat n "+\\'") s) ; "\'" バッファや文字列の末尾
(replace-match "" t t s)
s)))
@kobapan
kobapan / hook.php
Last active November 10, 2015 13:53
github に push すると、Webhooks 経由で、ウェブサーバ側が自動で git pull して、jekyll build して、rsync する感じのあれ
<?php
header('Content-Type: application/json');
$secret = 'パスワード';
$repo = 'リポジトリの名前';
function generate_response($code) {
$response = array(
'200' => array(
'status' => 'success',
'errors' => null
@kobapan
kobapan / mp4tomp3.sh
Created October 22, 2015 22:36
ffmpeg wrapper. comvert mp4 to mp3 in a current dir.
#!/bin/sh
while getopts dyh OPT
do
case $OPT in
"d" )
flag_d=1
;;
"y" )
flag_y="-y"
@kobapan
kobapan / frame-size-resume.el
Last active October 11, 2017 08:30
終了時のフレームサイズで起動する
(add-hook 'kill-emacs-hook 'frame-size-save); Emacs終了時
(add-hook 'window-setup-hook 'frame-size-resume); Emacs起動時
(defun frame-size-save ()
(set-buffer
(find-file-noselect (expand-file-name "~/.emacs.d/.framesize")))
(erase-buffer)
(insert (concat
"(set-frame-width (selected-frame) "
(int-to-string (frame-width))
") (set-frame-height (selected-frame) "
@kobapan
kobapan / between.el
Created March 25, 2015 10:51
elisp betweenマクロ
(defmacro between (var start end &optional $=)
`(cond ((null ,var) nil)
((numberp ,var)
(let (($$ (if ,$= '<= '<)))
(and (funcall $$ ,start ,var) (funcall $$ ,var ,end))))
((stringp ,var)
(if ,$=
(or (and (string< ,start ,var) (string< ,var ,end)) (string= ,start ,var) (string= ,var ,end))
(and (string< ,start ,var) (string< ,var ,end))))
(t (error "comparing neither numberp nor stringp"))))
@kobapan
kobapan / mapcar*.el
Created March 25, 2015 08:53
elisp mapcar*の使い方
(mapcar* 'cons '(a b c) '(1 2 3 4))
;=>((a . 1) (b . 2) (c . 3))
(mapcar* 'cons '(a b c) '(1 2 3 4) '(5 6 7))
;=>error
(mapcar* (lambda (a b c)
(+ a b c))
'(1 2 3)