Skip to content

Instantly share code, notes, and snippets.

@uemuraj
uemuraj / usradd.py
Created August 5, 2008 15:01
Apache ユーザの追加
#!/usr/bin/env python
# coding: utf-8
import sys
import md5
import binascii
from random import randint
from string import Template
from os import remove, rename
@uemuraj
uemuraj / test.groovy
Created January 31, 2012 14:38
さくらのクラウドのAPIを試してみた
#!/usr/bin/env groovy
def apikey = "99999999999999999999999"
def secret = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Authenticator.default = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication () {
return new PasswordAuthentication (apikey, secret.toCharArray());
}
@uemuraj
uemuraj / SimpleGraph.groovy
Created June 10, 2012 09:58
セマンティックWebプログラミングの第2章から第3章の内容を試す。
//
// セマンティックWebプログラミングの第2章から第3章の内容を試す。
//
class SimpleGraph {
// 各インデックスとも [ a : [ b : [ c, .. ] ] ] の様な格納方法
def spo = [:]
def pos = [:]
def osp = [:]
@uemuraj
uemuraj / s3.groovy
Created August 22, 2012 02:47
簡単な S3 用スクリプト
#!/usr/bin/env groovy
@Grab('com.amazonaws:aws-java-sdk:*')
import com.amazonaws.*
import com.amazonaws.auth.*
import com.amazonaws.services.identitymanagement.*
import com.amazonaws.services.identitymanagement.model.*
import com.amazonaws.services.s3.*
import com.amazonaws.services.s3.model.*
def options = new CliBuilder().with {
@uemuraj
uemuraj / amazon-linux-ami.groovy
Created September 5, 2012 01:37
Amazon Linux の最新版 AMI はどれ?
#!/usr/bin/env groovy
@Grab('com.amazonaws:aws-java-sdk:*')
import com.amazonaws.*
import com.amazonaws.auth.*
import com.amazonaws.services.ec2.*
import com.amazonaws.services.ec2.model.*
AWSCredentials credentials = new DefaultAWSCredentialsProviderChain().getCredentials()
ClientConfiguration config = new ClientConfiguration()
@uemuraj
uemuraj / GenericArray.java
Created September 6, 2012 23:34
ごくまれに必要になるジェネリックの形引数を調べる方法と、動的に任意の型の配列を作成する方法
import java.lang.reflect.Array;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/**
* ジェネリックから配列の動的生成の例:
*/
public class GenericArray<T> {
@SuppressWarnings("unchecked")
@uemuraj
uemuraj / gist.groovy
Created October 2, 2012 23:51
gist からファイルをダウンロードする簡単なスクリプト
#!/usr/bin/env groovy
import groovy.json.*
def options = new CliBuilder().with {
i(longOpt:'id', argName:'id', args:1, required:true, 'gist id')
p(longOpt:'prefix', argName:'prefix', args:1, 'save files to ${prefix}/...')
return it.parse(args)
}
if (options) {
@uemuraj
uemuraj / translate.groovy
Created October 11, 2012 23:53
microsoft-translator-java-api を利用した翻訳
#!/usr/bin/env groovy
@Grab('com.memetix:microsoft-translator-java-api')
import com.memetix.mst.language.Language
import com.memetix.mst.translate.Translate
//
// https://code.google.com/p/microsoft-translator-java-api/#Quickstart
//
// Set your Windows Azure Marketplace client info - See http://msdn.microsoft.com/en-us/library/hh454950.aspx
//
@uemuraj
uemuraj / BasicWebAPI.groovy
Created October 16, 2012 02:39
JAX-RS (Jersey) を利用した JSON/XML 両対応の簡単な Web サービスの実装
#!/usr/bin/env groovy
//
// http://weblogs.java.net/blog/lamineba/archive/2012/05/20/building-restful-web-services-jax-rs-jaxb-and-groovy
//
@Grab('com.sun.jersey:jersey-core')
@Grab('com.sun.jersey:jersey-json')
@Grab('com.sun.jersey:jersey-server')
import com.sun.jersey.api.container.ContainerFactory
@uemuraj
uemuraj / gist:3944078
Created October 24, 2012 05:10
Cassandra 用のデーモンスクリプト
#!/bin/sh
### BEGIN INIT INFO
# Provides: cassandra
# Required-Start: $local_fs $remote_fs $network $time $named
# Should-Start: $time sendmail
# Required-Stop: $local_fs $remote_fs $network $time $named
# Should-Stop: $time sendmail
# Default-Start: 3 5
# Default-Stop: 0 1 2 6