Skip to content

Instantly share code, notes, and snippets.

View ztrehagem's full-sized avatar
🥳

SUWA Shigeki ztrehagem

🥳
View GitHub Profile
@ztrehagem
ztrehagem / makeMoneyFormat
Last active November 9, 2015 01:37
convert int into money format string
public static String makeMoneyFormat(int money) {
StringBuilder str = new StringBuilder("");
StringBuilder target = new StringBuilder(String.valueOf(money % 1000));
while ((money /= 1000) > 0) {
while (target.length() < 3)
target.insert(0, "0");
str.insert(0, target);
str.insert(0, ",");
@ztrehagem
ztrehagem / rest-uri-parser.js
Last active March 2, 2017 15:17
rest uri parser / matcher
function parse(route, pathname) {
var keys = [];
var regexpstr = route.split('/').map(function(part) {
if (part.startsWith(':')) {
keys.push(part.substring(1));
return '([^/]+)';
} else {
return escape(part);
}
@ztrehagem
ztrehagem / rest-uri-builder.js
Created October 28, 2016 09:45
rest uri builder
function build(uri, params) {
console.log('@', uri, ' <- ', params);
var built = uri.replace(/\/:[^/]+/g, function(match) {
var key = match.substring(2);
return '/' + params[key];
});
console.log('built:', built);
}
build('/hoge/:fuga/:foobar', {
@ztrehagem
ztrehagem / mixin-hover.styl
Created May 13, 2019 01:52
disabling hover styles on touch/mobile devices
hover() {
/body:not(.__device-touchdevice) {selector()}:hover {
{block};
}
}
@ztrehagem
ztrehagem / mixin-media.styl
Created May 13, 2019 02:08
to avoid bug on stylus
media(query)
@media query
/{selector()}
{block}
tablet()
+media("screen and (max-width: 1023px)")
{block}
mobile()
const axios = {
get: (...args) => new Promise((resolve, reject) => {
console.log('called', args.join(', '));
setTimeout(() => resolve(args.join(', ')), 1500);
}),
};
const api = {
get: (...args) => new Promise((resolve, reject) => {
queue.push(async () => {
function toBooleanWithDefault (value: unknown, def: boolean) {
return typeof value === 'boolean' ? value : def
}
@mixin z-flow-flex($columns: 1, $margin-longitudinal: 0px, $margin-lateral: 0px, $child-selector: '*') {
display: flex;
flex-wrap: wrap;
> #{$child-selector} {
$width: calc((100% - #{$margin-lateral} * #{$columns - 1}) / #{$columns});
flex: 0 0;
flex-basis: $width;
width: $width;
const ALIGN_WEEK_NUM = false
const now = new Date()
const [
year = now.getFullYear().toString(),
month = (now.getMonth() + 1).toString(),
] = process.argv.slice(2)
const targetYear = parseInt(year)
class RandomAccessPool<T> {
readonly items: readonly T[]
protected pool: T[] = []
constructor(items: T[]) {
this.items = items
}
get() {
if (!this.pool.length) {