Skip to content

Instantly share code, notes, and snippets.

View hyamamoto's full-sized avatar

Hiroshi Yamamoto hyamamoto

View GitHub Profile
@hyamamoto
hyamamoto / NavigationQueue.java
Last active December 18, 2015 15:19
Over-engineered navigation queue. (Data structure for history token management)
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class NavigationQueue<E> {
private class NavigationQueueIterator<T> implements Iterator<T> {
private int op;
private int limit;
@hyamamoto
hyamamoto / MapValueByPath.java
Last active December 23, 2015 05:49
A utility class with a generic method to retrieve a value from a Map by a simple dot-separated path string ( A expression you would say... ‘Entity and Property’ style.) Maybe useful for expressing some of your data structure with a single string.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* A utility class to retrieve values from a map.<br/>
* (compatible with JDK 1.5)
@hyamamoto
hyamamoto / Comparing.java
Last active August 11, 2020 08:34
Generic null safe " Comparable.compareTo()" implementations.
/**
* Generic null safe {@link Comparable#compareTo(Object)} implementations.
*
* @author Hiroshi Yamamoto
* @see {@link Comparable}
*/
public final class Comparing {
private Comparing() {}
@hyamamoto
hyamamoto / Objects.java
Created November 12, 2013 09:24
GWT compatible java.util.Option class which is not emulated in current GWT 2.5.1. Put this in a super source package then the compiler will be able to see. Apparently, JDK folks took it from Guava's Optional class that is obviously a reinvention of the Option type in Scalalalaland.
package java.util;
/**
* <p>
* This class consists of {@code static} utility methods for operating on objects. These utilities include {@code null}-safe or {@code null}-tolerant
* methods for computing the hash code of an object, returning a string for an object, and comparing two objects.
* </p>
* <p>
* <i>This is a Java 5/6 compatible version of java.lang.Objects which has been introduced in Java 7</i>
* </p>
@hyamamoto
hyamamoto / install_git1.8.x_cygwin.md
Last active December 29, 2015 01:38
Installing the latest git (1.8.x) on Cygwin.

Installing the latest git on Cygwin

Cygwin always has older git (right now it has 1.7.9 released in May/2012. This needs an update to get around with has some unicode problems.)

Let's say a Windows junk was thrown at you. Git was not in that box. When you start looking at "msysgit", "Git for Windows", "Tortoise Git", "SourceTree" and "Github for Windows", you notice that they have all different git versions. Installing them, then you will end up with

@hyamamoto
hyamamoto / vimdiff.md
Created December 4, 2013 08:16
The vimdiff cheat sheet as a git mergetool.

vimdiff cheat sheet

This is a vimdiff cheat sheet as a git mergetool.

Commands

]c - go to next difference 
@hyamamoto
hyamamoto / GXT_TabPanel_WithButton.java
Created December 11, 2013 00:53
GXT Tips. Adding a GXT Button widget inside a tab bar right next to TabItems.
// Adding a GXT Button widget inside a tab bar right next to TabItems.
TabPanel folder = new TabPanel();
folder.addListener(Events.Render, new Listener<TabPanelEvent>() {
@Override
public void handleEvent(TabPanelEvent tpe) {
TabPanel tp = tpe.getContainer();
El strip = tp.el().childNode(0).childNode(0).childNode(0);
int clearIdx = strip.getChildIndex(strip.lastChild().dom);
Button button = new Button("Press!");
@hyamamoto
hyamamoto / vmcheck.dart
Last active August 29, 2015 13:56
"isClient", "isServer", "isDartClient", "isJsClient" properties to check if the Dart application is running whether on Javascript enabled browser, on Chronium browser, or as a server process.
library vmcheck;
import 'package:path/src/style.dart';
// This snippet is for Dart >= 1.1
bool get isClient => Style.platform == Style.url;
bool get isServer => Style.platform != Style.url;
@hyamamoto
hyamamoto / broadcast_basic.dart
Created March 3, 2014 06:23
Snippets to show basic use of "Dart Stream API" in case I forget. (written for dart-1.3.0-dev)
import 'dart:async';
void main() {
var data = [1,2,3,4,5];
var stream = new Stream.fromIterable(data);
var broadcastStream = stream.asBroadcastStream();
broadcastStream.listen((value) => print("(3)stream.listen: $value"));
broadcastStream.first.then((value) => print("(3)stream.first: $value")); // 1
@hyamamoto
hyamamoto / create_jpeg_then_send.dart
Last active October 16, 2020 13:31
A Dart snippet for "creating a JPEG image on client-side, then sending it to the server" .
import 'package:crypto/crypto.dart';
import 'dart:html';
import 'dart:typed_data';
void main() {
// Draw an on-memory image.
final CanvasElement canvas = document.createElement('canvas');
canvas.width = 256;
canvas.height = 256;