Skip to content

Instantly share code, notes, and snippets.

@relax-more
relax-more / ref
Created March 25, 2014 07:35
[python] with
http://shin.hateblo.jp/entry/2013/03/23/211750
@relax-more
relax-more / sample.py
Created March 25, 2014 07:50
[python] join
print '/'.join(['', 'usr', 'lib', 'python'])
@relax-more
relax-more / sample.py
Created March 25, 2014 08:01
[python] join with convert data to string
print ', '.join(str(x) for x in list_of_ints)
@relax-more
relax-more / gist:9828700
Created March 28, 2014 09:20
[java] is-null-check-needed-before-calling-instanceof
JFYI, I recently learned (or reconfirmed) that instanceof returns false for null.
So it's NPE-safe :)
http://stackoverflow.com/questions/2950319/is-null-check-needed-before-calling-instanceof
@relax-more
relax-more / snippet.py
Created April 1, 2014 06:42
[python] with keyword, file lock
with self.get_write_target_file('some_file') as write_target_file:
fcntl.flock(write_target_file, fcntl.LOCK_EX)
write_target_file.write('\t'.join(str(x) for x in data_list) + "\n")
fcntl.flock(write_target_file, fcntl.LOCK_UN)
@relax-more
relax-more / CryptUtil.java
Created April 24, 2014 02:31
[java] 暗号化 encrypt
public class CryptUtil {
private static final String DEFAULT_KEY_STRING = "12345678901234567890123456789012"
private static final String DEFAULT_TRANSFORMATION = "AES/ECB/PKCS5Padding";
public static Key generateKey(String keyString) {
if (keyString == null) {
keyString = DEFAULT_KEY_STRING;
}
int keylen = keyString.length();
if (keylen > 32) {
@relax-more
relax-more / snippet.sh
Created May 30, 2014 06:10
[shell] output message to standard error
if [ ! -f ${src} ]
then
echo Error message : ${src} >> /dev/stderr
fi
@relax-more
relax-more / beans-message.xml
Created June 3, 2014 04:58
[java] Load properties file as utf-8
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
@relax-more
relax-more / gist:ba596496b2a1c9308853
Created June 4, 2014 03:00
Currency display format list
http://www.thefinancials.com/Default.aspx?SubSectionID=curformat
@relax-more
relax-more / ExpectedExceptionTest.java
Created June 17, 2014 02:33
[java] expected test case configuration
@Test(expected= IndexOutOfBoundsException.class)
public void empty() {
new ArrayList<Object>().get(0);
}