Skip to content

Instantly share code, notes, and snippets.

View toshimaru's full-sized avatar

Toshimaru toshimaru

View GitHub Profile
@toshimaru
toshimaru / generateRandomString.py
Created June 10, 2012 04:49
python script which generate random string.
import string
from random import randrange
LENGTH = 10
alphabets = string.digits + string.letters
def randstr(n):
return ''.join(alphabets[randrange(len(alphabets))] for i in xrange(n))
if __name__ == '__main__':
@toshimaru
toshimaru / weekDays.php
Created June 10, 2012 05:50
output this week days.
<?php
$sunt = mktime(0, 0, 0, date("m"), date("d")-date("w"), date("Y")); // 今週の日曜日0時の時刻
for ($i = 0; $i < 7; $i++) {
$t = $sunt + $i * 60 * 60 * 24; //ワンステップで一日
$day = date("j", $t);
if ($day == date("j")) { //今日の場合
$day = "<b>{$day}</b>";
}
echo " <td>{$day}</td>\n";
}
@toshimaru
toshimaru / Dom4j.java
Created June 10, 2012 05:53
dom4j test.
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
public class Dom4jTest {
public static void main(String[] args) {
System.out.println("start");
String xml = "<root><element name='toshi'>text1</element><element2>text2</element2></root>";
try {
Document doc = DocumentHelper.parseText(xml);
@toshimaru
toshimaru / checktime.php
Created June 29, 2012 10:17
php checktime function
<?php
function checktime($hour, $min, $sec) {
if ($hour < 0 || $hour > 23 || !is_numeric($hour)) {
return false;
}
if ($min < 0 || $min > 59 || !is_numeric($min)) {
return false;
}
if ($sec < 0 || $sec > 59 || !is_numeric($sec)) {
return false;
@toshimaru
toshimaru / gist:3038546
Created July 3, 2012 08:43
camelize / decamelize function
<?php
/**
* via: http://d.hatena.ne.jp/fbis/20070713/1184309659
*/
function camelize ($str) {
return str_replace(' ','',ucwords(str_replace('_',' ',$str)));
}
function decamelize ($str) {
@toshimaru
toshimaru / gist:3065643
Created July 7, 2012 09:41
php get filename.
<?php
/**
* via: http://nanoca.me/relaxtyle/blog/2011/07/php-1.html
*/
// 現在表示されているファイル名取得
$path=$_SERVER["PHP_SELF"];
// パスつきのファイル名取得
$filename=basename($_SERVER["PHP_SELF"]);
@toshimaru
toshimaru / gist:3096075
Created July 12, 2012 05:43
add time to now.
<?php
print "1 hour later:" . date("Y/m/d H:i:s",strtotime("1 hour" ,strtotime(now))) . "<br>";
@toshimaru
toshimaru / gist:3120211
Created July 16, 2012 03:13
handle <a> click event with jQuery.
// via: http://docs.jquery.com/How_jQuery_Works
$(document).ready(function(){
$("a").click(function(event){
alert("As you can see, the link no longer took you to jquery.com");
event.preventDefault();
});
});
@toshimaru
toshimaru / gist:3128269
Created July 17, 2012 09:15
Japan prefecture array (日本の都道府県の配列)
<?php
$PREFECTURE = [
'1' => '北海道',
'2' => '青森県',
'3' => '岩手県',
'4' => '宮城県',
'5' => '秋田県',
'6' => '山形県',
'7' => '福島県',
'8' => '茨城県',
@toshimaru
toshimaru / gist:3357128
Created August 15, 2012 06:37
Action (C# delegate)
class Program
{
static void Main(string[] args)
{
int n = 10;
Action<int> act = (int i) =>
{
Console.WriteLine("num is : {0}", n * i);
};