Skip to content

Instantly share code, notes, and snippets.

@ngyuki
ngyuki / gist:3292015
Created August 8, 2012 04:25
フォームなどの Rectangle が画面内に収まるようにサイズや表示位置を調整する(マルチモニタ対応)
private Rectangle AdjustmentWindowBounds(Rectangle bounds)
{
var workarea = Screen.FromRectangle(bounds).WorkingArea;
if (workarea.Contains(bounds) == false)
{
if (bounds.Width > workarea.Width)
{
bounds.Width = workarea.Width;
}
@ngyuki
ngyuki / svn-change-author.sh
Created August 17, 2012 02:36
Subversion でユーザー名を一括置換する
#!/bin/bash
URL=http://example.com/repos/piyo/
DRY=0
OLD=hoge
NEW=fuga
for REV in $(svn log -q "$URL" | grep -w $OLD | awk '{print $1}'); do
VAL=$(svn propget svn:author --revprop -$REV "$URL")
@ngyuki
ngyuki / gist:3421011
Created August 22, 2012 00:52
svn で author の一覧を取得するワンライナー
# author の一覧を取得
svn log -q $URL | grep -v "^----" | cut -d "|" -f2 | sort | uniq
# 作業ディレクトリ内で実行する場合
svn log -q | grep -v "^----" | cut -d "|" -f2 | sort | uniq
@ngyuki
ngyuki / Lish_ErrorHandler_Thrown.php
Created August 22, 2012 03:26
[hatena 20120822] 特定のスコープでだけPHPエラーを例外としてスローするためのクラス
<?php
class Lish_ErrorHandler_Thrown
{
private $_original = false;
/**
* コンストラクタ
*/
public function __construct()
{
@ngyuki
ngyuki / pre-receive.sh
Created September 5, 2012 13:45
[hatena 20120905] Git でサーバに認証したユーザと Author が同じであることを強制するフックスクリプト
#!/bin/bash
RETVAL=0
while read HASH_OLD HASH_NEW REFNAME; do
(
git log --format=format:"%H%x09%an%x09%ae" ${HASH_OLD}..${HASH_NEW}
echo
) |
@ngyuki
ngyuki / gitlab-centos-init.sh
Created September 24, 2012 05:29
GitLab の CentOS 用の init スクリプト
#!/bin/bash
#
# GitLab
# Maintainer: @elvanja
# App Version: 2.8.2
# chkconfig: 2345 82 55
# processname: unicorn
# processname: rescue
# description: Runs unicorn and resque for nginx integration.
@ngyuki
ngyuki / post-receive.sh
Created September 25, 2012 12:51
redmine:fetch_changesets を実行する post-receive フック
#!/bin/sh
nohup sh -c 'cd /var/lib/redmine;sudo -u nobody rake redmine:fetch_changesets RAILS_ENV=production' 1> /dev/null 2>&1 &
<?php
class Hoge
{
protected $_val;
public function __construct($val)
{
$this->_val = $val;
}
@ngyuki
ngyuki / import.php
Created January 6, 2013 17:54
[qiita 20130107] クラスの静的メソッドを名前空間にインポートして修飾なしで呼ぶ
<?php
function import($ns, $klass)
{
$ref = new ReflectionClass($klass);
$methods = $ref->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC);
$code = "namespace $ns;\n";
/* @var $method ReflectionMethod */
foreach ($methods as $method)
@ngyuki
ngyuki / setuidgid.php
Last active December 11, 2015 11:19
PHP setuidgid.php
<?php
/*
* example)
* sudo php setuidgid.php apache test.php
*
*/
try
{
if ($argc <= 2)