Skip to content

Instantly share code, notes, and snippets.

@daichan4649
daichan4649 / TestServlet.java
Last active August 29, 2015 14:01
tomcat7 basic authentication
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();
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 January 4, 2024 17:09
[GAS] load SpreadSheet as JSON #spreadsheet #calendar #google
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++) {
@daichan4649
daichan4649 / AlarmUtil.java
Created December 27, 2013 01:30
毎朝10時にアラーム実行(指定Service起動)
public static void registerAlarm(Context context) {
// 現在
final Date nowDate = new Date();
Calendar now = Calendar.getInstance();
now.setTime(nowDate);
// 毎朝10:00
int alarmHH = 10;
int alarmMM = 0;
final String alarmHHMM = userInfo.getAlarm_time();
@daichan4649
daichan4649 / JsonicUtil.java
Created December 27, 2013 01:14
JSONIC でいろいろやるサンプル (Android)
package test.jsonic;
import net.arnx.jsonic.JSON;
public class JsonicUtil {
public enum ResponseType {
TEST_1(Test1Response.class), ;
private Class<? extends JsonResponse> decodeTargetClazz;
@daichan4649
daichan4649 / DebugUtil.java
Created December 27, 2013 00:59
テキスト内容をファイル出力 (Android)
public class DebugUtil {
private static final String DIRPATH_DEFAULT = "/mnt/sdcard/debug";
private static final String FILENAME_DEFAULT = "tmp.txt";
public static void flushText(String text) {
String path = String.format("%s/%s", DIRPATH_DEFAULT, FILENAME_DEFAULT);
flushText(text, path);
}
@daichan4649
daichan4649 / TestAdapter.java
Created December 24, 2013 02:27
TextView の文字色を default色 に戻す (Android)
public class TestAdapter extends ArrayAdapter<BindData> {
private LayoutInflater inflater;
private ColorStateList defaultColorStateList = null;
public TestAdapter(Context context, List<BindData> dataList) {
super(context, 0, dataList);
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@daichan4649
daichan4649 / GifView.java
Created December 19, 2013 07:52
GifView で1コマ目だけは本来の画像サイズより拡大(スケール)されて読み込まれる件の対応案
public void setGif(int resId) {
// Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resId);
BitmapFactory.Options opt = new Options();
opt.inScaled = false;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resId, opt);
setGif(resId, bitmap);
}
@daichan4649
daichan4649 / MainActivity.java
Last active December 31, 2015 19:28
ロック状態検知 (Android)
// permission は特に必要なし
// アプリ起動時に登録
private void registerKeyguardReceiver() {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_USER_PRESENT);
filter.addAction(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(mKeyguardReceiver, filter);
}
@daichan4649
daichan4649 / AndroidManifest.xml
Created December 13, 2013 04:16
custom ActionBar
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="CustomActionBarActivity"
android:label="@string/title_activity_custom_actionbar"
android:theme="@style/Theme.Custom" />
</application>