Skip to content

Instantly share code, notes, and snippets.

View daicham's full-sized avatar

Daisuke Takeuchi daicham

View GitHub Profile
@daicham
daicham / Vagrantfile
Created July 15, 2014 03:57
Vagrantfile for ec2
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "dummy"
config.vm.provider :aws do |aws, override|
@daicham
daicham / gist:10253947
Last active June 1, 2021 22:02
SSH config for connecting to github and bitbucket over proxy
ProxyCommand "C:\Program Files\git\bin\connect.exe" -H proxy.example.com:8080 %h %p
Host github.com
HostName ssh.github.com
Port 443
IdentityFile C:\Users\hoge\.ssh\id_rsa
Host bitbucket.org
HostName altssh.bitbucket.org
Port 443
IdentityFile C:\Users\hoge\.ssh\id_rsa
// Proxy 設定は %USERPROFILE%\.groovy\preinit.bat に JAVA_OPTS として記述する。
// ex.)
// set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=proxyserver -Dhttp.proxyPort=8080 -Dhttp.proxyUser=username -Dhttp.proxyPassword=secret
// set JAVA_OPTS=%JAVA_OPTS% -Dhttps.proxyHost=proxyserver -Dhttps.proxyPort=8080 -Dhttps.proxyUser=username -Dhttps.proxyPassword=secret
@GrabResolver(name="kobo", root="https://repository-kobo.forge.cloudbees.com/release")
@Grab("org.jggug.kobo:gexcelapi:0.3")
import org.jggug.kobo.gexcelapi.GExcel
def book = GExcel.open(args[0])
@daicham
daicham / gist:4528511
Last active January 9, 2019 13:14
zip/unzip on Powershell (depends on Ionic.Zip.dll)
function zip ($zipFilePath, $targetDir) {
# load Ionic.Zip.dll
[System.Reflection.Assembly]::LoadFrom(path\to\Ionic.Zip.dll)
$encoding = [System.Text.Encoding]::GetEncoding("shift_jis") # 日本語のファイルを扱うために必要
$zipfile = new-object Ionic.Zip.ZipFile($encoding)
$zipfile.AddDirectory($targetDir)
if (!(test-path (split-path $zipFilePath -parent))) {
mkdir (split-path $zipFilePath -parent)
@daicham
daicham / redmine.py
Last active December 10, 2015 23:08
Request Redmine SCM fetching by http on Python (Tested for Mercurial)
# usase:
# python redmine.py projectname1, projectname2
import sys, httplib
REDMINE_HOST = 'localhost:3000'
URL = '/redmine/sys/fetch_changesets?id=%s&key=%s'
REDMINE_API_KEY = 'token'
redmine_project_ids = sys.argv
redmine_project_ids.pop(0) # shift operation to reduce this command
@daicham
daicham / jenkins.py
Created January 11, 2013 01:16
Request jenkins job by http on Python (Tested for Mercurial)
# usage:
# python jenkins.py jobname1, jobname2
import sys, httplib
JENKINS_HOST = 'localhost:8080'
URL = '/jenkins/job/%s/build?token=%s&cause=%s'
JENKINS_AUTH_TOKEN = 'token'
CAUSE='Requested%20by%20Python'
jenkins_job_ids = sys.argv
@daicham
daicham / gist:4109527
Created November 19, 2012 08:08
A sample ruby code of executing SQL for Oracle
# encoding: utf-8
#
# Prerequisite:
# gem install ruby-oci8
require 'oci8'
def log(message)
puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} #{message}"
end
@daicham
daicham / gist:3926165
Created October 21, 2012 06:41
Sample code of MongoDB Aggregtion query
// 日付とカウンタが入ったドキュメントのうち 2012/10/21 のみを時間別に count を集計するクエリ
db.journal.group(
{
//集計対象のドキュメント条件
cond: {
created: {$gte: ISODate("2012-10-21 00:00:00"), $lt: ISODate("2012-10-22 00:00:00")}
},
//集合キーを生成するための関数
keyf: function(doc) {
var time = doc.created.getHours();
@daicham
daicham / gist:2934926
Last active October 6, 2015 04:18
Redmine Backup Script by Groovy
//Dump from mysql
/* dump ファイルが文字化けしたので コマンドラインから sqldump したほうがよさそう
def mysqldump_process = "/path/to/mysqldump -u redmine -psecret redmine".execute()
new File("redmine.dump").withWriter { writer ->
writer << mysqldump_process.text
}
*/
//Archive dump and attachedfiles
new AntBuilder().zip(destfile: "path/to/backup/redmine-backup." + new Date().format("yyyyMMddHHmmss") + ".zip",
@daicham
daicham / gist:2145516
Created March 21, 2012 07:45
Print the directory structure and its actual size
def print_tree(base_dir)
base_dir = base_dir + '/' unless base_dir.end_with? '/'
size = 0
Dir.glob("#{base_dir}*/") do |dir|
#puts "entering #{dir}"
size += print_tree dir
end
Dir.glob("#{base_dir}*") do |file|
real_size = File.size file
size += compute_actual_size real_size