Skip to content

Instantly share code, notes, and snippets.

View ypresto's full-sized avatar
🏠
Working from home

Yuya Tanaka ypresto

🏠
Working from home
View GitHub Profile
# Place this file on /etc/update-ddns.conf
# SECURITY: run `chmod 600 /etc/update-ddns.conf'
# to make it unreadable by non-root users.
DOMAIN=
PASSWORD=
HOST=
@ypresto
ypresto / SqaureFrameLayout.java
Created May 15, 2014 04:03
Keep aspect ratio to 1:1. Not tested.
package net.ypresto.utils.squareview;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
/**
* FrameLayout enforces its aspect ratio to 1:1.
* NOTE: wrap_content is not supported.
*/
@ypresto
ypresto / gist:6d299f8a3e0b82b1b3b3
Last active August 29, 2015 14:11
dentry memory bloat inspection
$ uname -a
Linux (hostname) 3.14.25-23.45.amzn1.x86_64 #1 SMP Wed Dec 3 21:29:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/sys/vm/vfs_cache_pressure
100
$ free -m
total used free shared buffers cached
Mem: 996 922 74 0 28 133
-/+ buffers/cache: 760 236
#!/bin/sh
message="$TRAVIS_REPO_SLUG $TRAVIS_BRANCH build failed <!channel>"
payload="payload={\"text\": \"${message}\"}"
curl --silent --max-time 5 --data "${payload}" "https://hooks.slack.com/services/${SLACK_TOKEN}" | grep -Ei '^ok$' > /dev/null || echo 'Failed to notify.'
@ypresto
ypresto / sed-inplace.sh
Last active November 3, 2015 17:00
Shell command for replacing all texts in all files under specified paths
sed-inplace () {
if (( $# < 2 )); then
echo "sed-inplace FROM TO [PATH ...]"
return 1
fi
from="$1"
to="$2"
shift 2
ag -l "$from" "$@" | while read file; do
if [ "`uname`" = "Darwin" ]; then # please, please give me portable sed...
@ypresto
ypresto / MCLayoutGuideHelper.h
Last active February 13, 2016 05:35
Apply Top/Bottom Layout Guide (or automaticallyAdjustsScrollViewInsets) to embedded (to Container View) View Controller
/*
* MCLayoutGuideHelper.h
* Yuya Tanaka
*
* This is free and unencumbered software released into the public domain.
*
* Anyone is free to copy, modify, publish, use, compile, sell, or
* distribute this software, either in source code form or as a compiled
* binary, for any purpose, commercial or non-commercial, and by any
* means.
#!/bin/bash
# Place this on chroot target dir.
umount=0
[ "$1" = "-u" ] && umount=1
for dir in dev proc sys; do
if (( $umount )); then
umount ./$dir
@ypresto
ypresto / SubscriptionUtils.java
Last active March 30, 2017 09:13
.lift(SubscriptionUtils.composite(mCompositeSubscription)) and forget about subscriptions but composite one.
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action0;
import rx.subscriptions.CompositeSubscription;
import rx.subscriptions.Subscriptions;
public class SubscriptionUtils {
/**
* Automatically adds to / removes from specified {@link CompositeSubscription} when subscribe / unsubscribe is called.
* Useful when subscribing observable repeatedly, as you do not need to manipulate CompositeSubscription manually.
@ypresto
ypresto / FragmentItemIdStatePagerAdapter.java
Created July 13, 2015 14:28
Modified FragmentStatePagerAdapter which correctly handles reordering of items and saved states. Original issue: https://code.google.com/p/android/issues/detail?id=37990
/*
* Copyright (C) 2011 The Android Open Source Project
* Copyright (C) 2015 Yuya Tanaka
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ypresto
ypresto / brook-rxjs-bridge.js
Last active August 29, 2015 14:27
Translate brook promise and channel into RxJS.
Namespace('brook.rxjsbridge')
.use('brook promise')
.define(function(ns) {
'use strict';
var observableFromPromise = function(promise, value) {
return Rx.Observable.create(function(observer) {
var called = false;
var throwIfCalled = function() {
if (called) {
throw new Error('promise resolved twice.');