Skip to content

Instantly share code, notes, and snippets.

View pistatium's full-sized avatar
🚲
Cycling

kimihiro_n pistatium

🚲
Cycling
View GitHub Profile
@pistatium
pistatium / timeago.py
Created April 15, 2016 03:02
timeago
from datetime import timedelta, datetime
from django.utils import timezone
from django.test import TestCase
from django import template
register = template.Library()
@register.filter()
def timeago(dt: datetime, now_dt: datetime=None) -> str:
@pistatium
pistatium / exercise-equivalent-binary-tree.go
Last active January 28, 2016 02:53
Exercise: Equivalent Binary Trees
package main
import (
"fmt"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
@pistatium
pistatium / file0.html
Created January 24, 2014 10:37
Django Templateのif-elseを短く書く ref: http://qiita.com/pistatium@github/items/f85e44d29d36982480aa
{% if param.status == 1 %}
<!-- 特定の条件の場合activeというクラス名をつける -->
<li class="active">
{% else %}
<li>
{% endif %}
<a href="#">Active</a>
</li>
……
@pistatium
pistatium / file0.php
Created January 21, 2014 10:02
XMLからJSON形式への変換メモ(PHP) ref: http://qiita.com/pistatium@github/items/7cfcd4ccb91c6f4c43e9
$obj = simplexml_load_string($xml);
$json = json_encode($obj);
@pistatium
pistatium / AndroidManifest.xml
Created January 10, 2014 01:29
ActiveAndroidをContentProvider経由で使うメモ ref: http://qiita.com/pistatium@github/items/0092a2c4758e12481df9
<provider
android:name="com.activeandroid.content.ContentProvider"
android:authorities="APKのパッケージ名" />
import markdown
md = markdown.Markdown()
sample_makedown = '''
An h1 header
============
Paragraphs are separated by a blank line.
@pistatium
pistatium / DailyScheduler.java
Created November 15, 2013 09:12
DailyScheduler
package com.appspot.pistatium.tomorrow.service;
import java.util.Calendar;
import java.util.TimeZone;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@pistatium
pistatium / hexTo64.py
Created November 14, 2013 10:41
MD5のような16進数の文字列をA-Z a-z 0-9 + _ の64文字で表すための関数
#!/usr/local/bin/python2.7
import md5
def hexTo64(hex):
result = []
for i in range(8):
# 16 * 16 / 4 = 64
tmp = int(hex[i * 2: i * 2 + 2],16) / 4
if tmp < 26:
# A-Z
@pistatium
pistatium / TableBuilder.js
Last active December 19, 2015 13:39
= Table Builder = JSON等から手っ取り早くTableタグを生成する用の関数
/*
データを手っ取り早くテーブルにして表示するための関数
何を表示するかを定義したheaderと、
配列形式で複数行のデータが入ったdataを渡すと
テーブルのHTMLを返す
*/
var tableBuilder = function(header, data) {
var html = '<table class="table"><thead><tr>';
for (var key in header) {
html += '<th id="label_' + key + '">' + header[key] + '</th>';
@pistatium
pistatium / php_foreach.php
Last active December 19, 2015 09:09
foreach trap
<?php
$arr = array(
"first" => 1,
"second" => 2,
);
echo "\nBefore \n";
print_r($arr);