Skip to content

Instantly share code, notes, and snippets.

View narusemotoki's full-sized avatar

Motoki Naruse narusemotoki

View GitHub Profile
@narusemotoki
narusemotoki / dirwatch.py
Created November 12, 2012 12:35
ディレクトリを監視して,ファイルに変更があった場合に任意のコマンドを実行します.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import datetime
import time
import os
from stat import *
import commands
def watch(dir, command):
@narusemotoki
narusemotoki / quakeapp.py
Created November 14, 2012 14:15
任意のアプリケーションを最前面に移動したり,最小化するプログラム
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from subprocess import PIPE, Popen
import os
import sys
def get_current_window_name():
for i in Popen(['xprop', '-root'], stdout=PIPE).stdout:
if '_NET_ACTIVE_WINDOW(WINDOW):' in i:
for j in Popen(['xprop', '-id', i.split()[4]], stdout=PIPE).stdout:
@narusemotoki
narusemotoki / tailer.py
Created July 30, 2012 15:30
日付などでファイルが切り替わるログをtailで表示します.新しいファイルができると,そちらに切り替わります.引数でログファイルが置かれるディレクトリを指定してください.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import time
import subprocess
from threading import Thread
import signal
use std::cell::RefCell;
use std::rc::Rc;
type Link<T> = Rc<RefCell<Node<T>>>;
pub struct Node<T: Copy> {
value: T,
next: Option<Link<T>>,
}
@narusemotoki
narusemotoki / fib.sql
Created March 12, 2018 08:48
フィボナッチSQL
WITH RECURSIVE fib (m, n) AS (
SELECT 1, 1
UNION ALL
SELECT n, m + n FROM fib
)
SELECT m FROM fib
LIMIT 10
;
m
----
#!/bin/bash
cd ~
echo "apt-getを使用するためにパスワードを入力"
sudo apt-get update
sudo apt-get install -y zsh
echo "シェルをzshに変更するためにパスワードを入力"
chsh -s /bin/zsh
@narusemotoki
narusemotoki / setuppi.sh
Last active December 31, 2015 08:08
自分用のRaspberry Piのセットアップ用シェルスクリプト wget https://gist.github.com/narusemotoki/7958192/raw/4d609fc04d29ce48d1554f6aab977a644688e941/setuppi.sh; bash setuppi.sh
#!/bin/bash
# sudo dd if=~/Downloads/2013-09-25-wheezy-raspbian.img of=/dev/sdb
# sudo raspi-config
echo -n "What's this ip address?: "
read IP_ADDRESS
sudo apt-get update
sudo apt-get install -y libsqlite3-dev libssl-dev python-pip emacs
sudo pip install virtualenv virtualenvwrapper
#!/bin/bash
cd ~
echo "apt-getを使用するためにパスワードを入力"
sudo apt-get update
sudo apt-get install -y zsh
echo "シェルをzshに変更するためにパスワードを入力"
chsh -s /bin/zsh
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class _Singleton(type):
"""
Python 2.xと3.xの両方をサポートするためには、このように継承しなければならない。
class SubClass(_Singleton('Singleton', (object, ), {})):
pass
@narusemotoki
narusemotoki / gitprepush.sh
Created July 7, 2013 13:59
git push -nを行い、pushするコミットがあった場合いに、それらのログを表示します。 パスの通った場所にgitprepush.shを置き、実行権限を与えてください。 .gitconfigにprepush = "! gitprepush.sh"を書くとgit prepushと利用できるようになります。
#!/bin/sh
# Copyright (c), Naruse Motoki (motoki@naru.se)
# Licensed under The MIT License
dryrun=`git push -n 2>&1`
echo "$dryrun"
fromto=`echo $dryrun | sed -e "s/.* \([0-9a-z]\+\.\.[0-9a-z]\+\) .*/\1/g"`
if expr "$fromto" : "^[0-9a-z]\+\.\.[0-9a-z]\+$" >/dev/null; then
echo "`git log --date=short --pretty=format:"%h %ad %an %s" $fromto`"
fi