Skip to content

Instantly share code, notes, and snippets.

View toshimaru's full-sized avatar

Toshimaru toshimaru

View GitHub Profile
@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 / 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 / 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 / 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: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);
};
@toshimaru
toshimaru / gist:3486237
Created August 27, 2012 06:28
masking string
<?php
/**
* masking string
*
* @param string @secretStr
* @return string
*/
function masking($secretStr) {
return str_repeat('*', strlen($secretStr));
}
@toshimaru
toshimaru / gist:3495190
Created August 28, 2012 05:23
circle with css3
.circle {
background-color: #cc3;
height: 150px;
width: 150px;
border-radius:75px;
-moz-border-radius:75px;
-webkit-border-radius: 75px;
}