Skip to content

Instantly share code, notes, and snippets.

Daisuke Hirata daichan4649

Block or report user

Report or block daichan4649

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@daichan4649
daichan4649 / DebugUtil.java
Created Dec 9, 2014
JavaEE 環境でクラスパス配下のファイルを文字列として読み込む(JSON等)
View DebugUtil.java
// dir name(class pathをルートとする相対パス)
private static final String DIR_NAME = "json";
private static final String FILE_NAME = "test.json";
public static String createJsonText(Class<? extends HttpServlet> clazz) {
return createJsonText(clazz, DIR_NAME, FILE_NAME);
}
public static String createJsonText(Class<? extends HttpServlet> clazz, String dirName, String fileName) {
String dirPath = clazz.getClassLoader().getResource(dirName).getPath();
@daichan4649
daichan4649 / AndroidManifest.xml
Created Sep 11, 2014
wifi setting notification (for Android)
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="daichan4649.notification"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="20" />
@daichan4649
daichan4649 / AndroidManifest.xml
Last active Oct 7, 2015
各種通知(notification, toast) をアプリ側で検知する (for Android)
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="daichan4649.notification"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="20" />
@daichan4649
daichan4649 / Util.java
Last active Aug 29, 2015
クラスパス内ファイルのフルパス取得
View Util.java
// クラスパスルートからの相対パスを指定
private static final String relativePath = "/resources/aaa.txt";
private String getRealResourcePath(String relativePath) {
return getClass().getClassLoader().getResource(relativePath).getPath();
}
@daichan4649
daichan4649 / ZipUtil.java
Last active Aug 29, 2015
unzip (for Java)
View ZipUtil.java
public static void unzip(String zipFilePath, File dstDir) {
try {
final ZipFile zipFile = new ZipFile(zipFilePath);
Enumeration<? extends ZipEntry> enumZip = zipFile.entries();
while (enumZip.hasMoreElements()) {
final ZipEntry zipEntry = enumZip.nextElement();
// 出力先設定
File dstFile = new File(dstDir, zipEntry.getName());
if (dstFile.isDirectory()) {
@daichan4649
daichan4649 / PropertyUtil.java
Last active Aug 29, 2015
Servletでのプロパティファイル読み書き
View PropertyUtil.java
public class PropertyUtil {
private static final String PROPERTY_FILE_TEST = "test.properties";
public static void setTestPropertyValue(ServletContext context, String key, String value) {
setPropertyValue(context, PROPERTY_FILE_TEST, key, value);
}
public static String getTestPropertyValue(ServletContext context, String key) {
return getPropertyValue(context, PROPERTY_FILE_TEST, key);
@daichan4649
daichan4649 / IpListServlet.java
Created May 29, 2014
アクセスログ保存/一覧表示 (jQuery, JSON, JavaEE6)
View IpListServlet.java
package test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@daichan4649
daichan4649 / TestServlet.java
Last active Aug 29, 2015
tomcat7 basic authentication
View TestServlet.java
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// logon user name
final String userName = request.getUserPrincipal().getName();
PrintWriter out = response.getWriter();
out.println(String.format("doGet(%s)", userName));
out.flush();
out.close();
View HelloResource.java
package test;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
// http://localhost:8080/JerseySample/sample/hello?name=aaa&age=100
@Path("/hello")
public class HelloResource {
@daichan4649
daichan4649 / convertSheet2Json.gs
Last active Jun 18, 2019
spreadsheet のデータを JSON として読み込む(Google Apps Script)
View convertSheet2Json.gs
function convertSheet2Json(sheet) {
// first line(title)
var firstRange = sheet.getRange(1, 1, 1, sheet.getLastColumn());
var firstRowValues = firstRange.getValues();
var titleColumns = firstRowValues[0];
// after the second line(data)
var lastRow = sheet.getLastRow();
var rowValues = [];
for(var rowIndex=2; rowIndex<=lastRow; rowIndex++) {
You can’t perform that action at this time.