Skip to content

Instantly share code, notes, and snippets.

View musubu's full-sized avatar

Musubu Inc. musubu

View GitHub Profile
@musubu
musubu / validates_timeliness.ja.yml
Created June 16, 2013 04:53
validates_timelinessの日本語ロケール
ja:
errors:
messages:
invalid_date: "は不正な日付です。"
invalid_time: "は不正な時間です。"
invalid_datetime: "は不正な日時です。"
is_at: "は%{restriction}にしてください。"
before: "は%{restriction}より前にしてください。"
on_or_before: 'は%{restriction}以前にしてください。'
after: "は%{restriction}より後にしてください。"
@musubu
musubu / redis.sh
Created February 4, 2013 03:14
redisの起動スクリプト /etc/init.d/redis
#!/bin/sh
#
# redis init file for starting up the redis daemon
#
# chkconfig: - 20 80
# description: Starts and stops the redis daemon.
# Source function library.
. /etc/rc.d/init.d/functions
@musubu
musubu / hero.jade
Created November 6, 2012 23:15
hero.jade Bootstrapのサンプルのhero.htmlをjadeで書きなおしたもの
!!! 5
html(lang='en')
head
meta(charset='utf-8')
title Bootstrap, from Twitter
meta(name='viewport', content='width=device-width, initial-scale=1.0')
meta(name='description', content='')
meta(name='author', content='')
// Le styles
link(href='../assets/css/bootstrap.css', rel='stylesheet')
@musubu
musubu / node-project.gitignore
Created October 17, 2012 05:49
gitignore skelton for node.js project
# https://raw.github.com/github/gitignore/master/Global/OSX.gitignore
.DS_Store
.AppleDouble
.LSOverride
Icon
# Thumbnails
._*
@musubu
musubu / trim.js
Created September 11, 2012 03:26
Trim in JavaScript
// 全角スペースがある場合は半角スペースに置換されます
trim: function(string, callback){
var callbackExists = false;
if (callback && typeof(callback) === 'function') callbackExists = true;
try {
string = string.replace(/ /g, ' ').replace(/(^\s+)|(\s+$)/g, "");
if (callbackExists) callback(null, string);
else return string;
} catch (e) {
@musubu
musubu / datetime_convert.js
Created August 21, 2012 06:01
JavaScriptのDateをMySQLのdatetimeに入力できる書式に変換する
var str_created_at = 'Sun Dec 11 21:44:28 +0000 2011';
var created_at = new Date(str_created_at);
console.log(created_at)
// Mon Dec 12 2011 06:44:28 GMT+0900 (JST)
function toUTCDatetime (date, callback) {
try {
var result = date.getUTCFullYear() + "-" + date.getUTCMonth() + "-" + date.getUTCDate() + " " + date.getUTCHours() + ":" + date.getUTCMinutes() + ":" + date.getUTCSeconds();
callback(null, result);
} catch (err) {
@musubu
musubu / StringUtils.java
Created July 11, 2012 07:58
文字列の前後の全角スペースおよび半角スペースを除去
package utils;
/**
* @author Musubu Inc.
*/
public class StringUtils {
private static final String SPACE_CHAR_HALF = " ";
private static final String SPACE_CHAR_WIDE = " ";
/**
@musubu
musubu / gist:3087294
Created July 11, 2012 01:18
remove a trailing slash from a string in Java
s = s.replaceAll("/$", "");
// or
s = s.replaceAll("/\\z", "");
// slightly faster
if (s.endsWith("/")) {
s = s.substring(0, s.length() - 1);
@musubu
musubu / ZipUtils.java
Created June 27, 2012 06:44
Unzip in Java
package utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;