Skip to content

Instantly share code, notes, and snippets.

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

Yuichi Araki yaraki

🏠
Working from home
  • Google, Inc.
  • Tokyo
View GitHub Profile
@yaraki
yaraki / minitest.cpp
Last active August 29, 2015 14:11
Minimal testing
// clang++ -o minitest minitest.cpp -std=c++1y -stdlib=libc++
#include <iostream>
#define TEST_PREDICATE(expr, oper) \
do { \
auto expr__ = (expr); \
if (!(expr__ oper)) { \
std::cout << __FILE__ << ":" << __LINE__ << " " \
<< "FAILED " << #expr << " " << #oper \
package com.arakitech.kotlisp
import java.util.HashMap
fun StringBuilder.clear() {
this.setLength(0)
}
class Tokenizer(val input: String) {
private var position = 0
@yaraki
yaraki / channel.cpp
Created February 17, 2015 15:11
Go-style channel in C++
#include <iostream>
#include <list>
#include <thread>
namespace ya {
template<class item_t>
class channel {
private:
@yaraki
yaraki / simple-sine.el
Created July 7, 2015 08:22
Simple sine calculation by taylor expansion
(defconst if3 (* 2 3))
(defconst if5 (* if3 4 5))
(defconst if7 (* if5 6 7))
(defconst if9 (* if7 8 9))
(defconst if11 (* if9 10 11))
(defun simple-sine (x)
(unless (eq 'float (type-of x))
(setf x (float x)))
(let* ((x2 (* x x))
@yaraki
yaraki / forth.lisp
Created September 12, 2015 13:28
Toy forth implementation in Common Lisp
(in-package :cl-user)
(defpackage forth
(:use :cl)
(:export :run
:clear
:create-context))
(in-package :forth)
(defstruct context
(dictionary (make-hash-table :test 'equal))
@yaraki
yaraki / BottomSheetModal.java
Created February 25, 2016 10:11
Modal Bottom Sheet
/*
* Copyright (C) 2015 The Android Open Source Project
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
@yaraki
yaraki / CheckerView.java
Created February 20, 2017 07:06
Android View that shows a dummy checkered pattern
/*
* Copyright (C) 2017 The Android Open Source Project
*
* 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
*
* Unless required by applicable law or agreed to in writing, software
@yaraki
yaraki / gc.c
Created September 14, 2017 12:44
Simple GC
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef enum _Type Type;
enum _Type {
TYPE_INT,
TYPE_PAIR,
};
@yaraki
yaraki / main_activity.xml
Last active June 25, 2018 05:51
Place an icon at the end of a "wrap_content" text view
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
@yaraki
yaraki / ClockLiveData.kt
Last active December 21, 2019 07:02
This LiveData provides the time in hh:mm:ss format, updating the value every second
package io.github.yaraki.dependencyinjection
import android.arch.lifecycle.LiveData
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.text.format.DateFormat
import java.util.*
class ClockLiveData : LiveData<CharSequence>() {