Skip to content

Instantly share code, notes, and snippets.

View jinahya's full-sized avatar

Jin Kwon jinahya

  • Wemakeprice
  • Seoul, Korea
View GitHub Profile
import static java.lang.Double.doubleToLongBits;
import static java.lang.Float.floatToIntBits;
import static java.lang.Integer.toBinaryString;
import static java.lang.Long.toBinaryString;
import static java.lang.String.format;
public class FloatingPoints {
private static String ieee754s(final int value) {
import java.util.logging.Logger;
public enum EnumWithLogger {
//private static Logger logger; // can't place here
NONE {
void world() {
slogger.info("world");
@jinahya
jinahya / FloatIntBits.java
Created March 19, 2016 13:03
FloatIntBits.java
public class FloatIntBits {
private static void printIntBits(float value) {
System.out.println("-------------------------------------");
System.out.printf(" value: %f\n", value);
final int intBits = Float.floatToIntBits(value);
final int rawIntBits = Float.floatToRawIntBits(value);
System.out.printf(" toIntBits: 0x%08x %f\n", intBits, Float.intBitsToFloat(intBits));
System.out.printf("toRawIntBits: 0x%08x %f\n", rawIntBits, Float.intBitsToFloat(rawIntBits));
}
#!/bin/sh
# by Jin Kwon <onacit_at_gmail.com>
# fetches all https://github.com/gruntjs/grunt-init-*.git repositories
# into to your ~/.grunt-init
# and (or) pull them all
# this script uses 'jq' command
gruntinit=~/.grunt-init
if [ ! -d $gruntinit ]; then
echo making directory $gruntinit
mkdir $gruntinit
*ini*
@jinahya
jinahya / PrintNumberReverse.java
Last active December 22, 2016 13:48
How to print given number in reversed order?
public class PrintNumberReverse {
static void method1(final int number) {
final char[] chars = Integer.toString(number).toCharArray();
for (int i = chars.length -1; i >= 0; i--) {
System.out.print((char) chars[i]);
}
System.out.println();
}
@jinahya
jinahya / VerifyOpenClose.java
Last active December 22, 2016 14:14
How to verify a sequence of parentheses.
import java.util.ArrayList;
import java.util.List;
public class VerifyOpenClose {
private static final List<Character> parentheses = new ArrayList<Character>(){
{
// odd -> opening
// even -> cloosing
add('('); // 0 opening
@jinahya
jinahya / Property.java
Created January 26, 2017 06:23
Injecting Property Values into EJBs from Database
@Entity
@NamedQueries({
@NamedQuery(name = "Property.find",
query = "SELECT p FROM Property AS p WHERE p.name = :name")
})
public class Property extends BaseEntity {
public static Property findNamed(final EntityManager entityManager,
final String name) {
final TypedQuery<Property> typedQuery
@jinahya
jinahya / TheThreeLawsOfRobotics.md
Last active January 27, 2017 07:03
The Three Laws of Robotics, I, Robot, Isaac Asimov

The Three Laws of Robotics

  1. A robot must not harm a human. And it must not allow a human to be harmed.
  2. A robot must obey a human's order, unless that order conflicts with the First Law.
  3. A robot must protect itself, unless this protection conflicts with the First or Second Laws.

Handbook of Robotics, 2058 A.D.

@jinahya
jinahya / CountDownLatchDemo.java
Last active March 1, 2017 07:05
A demo using CountDownLatch
import java.util.concurrent.CountDownLatch;
import static java.util.concurrent.ThreadLocalRandom.current;
public class CountDownLatchDemo {
public static void main(final String[] args) throws InterruptedException {
final int count = 100;
final CountDownLatch latch1 = new CountDownLatch(count);
final CountDownLatch latch2 = new CountDownLatch(count);
for (int i = 0; i < count; i++) {
new Thread(() -> {
try {