Skip to content

Instantly share code, notes, and snippets.

View jinahya's full-sized avatar

Jin Kwon jinahya

  • Wemakeprice
  • Seoul, Korea
View GitHub Profile
@jinahya
jinahya / reverse.c
Last active August 29, 2015 14:22
functions reserve an array
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int reverse(void * array, const size_t offset, const size_t length, const size_t size) {
void * temp = malloc(size);
if (temp == NULL) {
return EXIT_FAILURE;
}
@jinahya
jinahya / swap.c
Last active August 29, 2015 14:23
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define swapa(type, a, b) { type t = a; a = b; b = t; }
#define swapb(type, a, b) { type t = *a; *a = *b; *b = t; }
class ArrOffLen<T> {
public boolean isValid() {
if (arr == null) {
return false;
}
if (off < 0) {
return false;
}
if (len < 0) {
public class CodeSnippetsInJavadoc {
/**
* Prints {@code hello, world\n} to {@code stdout}.
*
* <blockquote><pre>{@code
* public static void main(final String[] args) {
* System.out.printf("hello, world\n");
* }
* }</pre></blockquote>
@jinahya
jinahya / setup-x86_64.ps1
Last active November 19, 2015 22:35
updating cygwin installer itself and invoking it.
$file = "setup-x86_64.exe"
Invoke-WebRequest -OutFile $file https://www.cygwin.com/$file
Invoke-Expression .\$file
@jinahya
jinahya / pom.xml
Last active November 19, 2015 22:35
enforcing dependency convergence
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>enforcer-dependency-convergence-test</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
import java.nio.ByteBuffer;
import java.util.Arrays;
import static java.util.concurrent.ThreadLocalRandom.current;
public class ArrayWrappingByteBufferTest {
public static void main(final String[] args) {
final byte[] array = new byte[] {1, 1, 1, 1, 1, 1, 1, 1};
System.out.println("array: " + Arrays.toString(array));
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/beans_1_1.xsd">
</beans>
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));
}