Skip to content

Instantly share code, notes, and snippets.

View Korilakkuma's full-sized avatar

Tomohiro IKEDA Korilakkuma

View GitHub Profile
@Korilakkuma
Korilakkuma / clipboard.html
Last active August 29, 2015 14:07
Use ZeroClipboard.js
<!DOCTYPE html>
<html lang="ja">
<head>
<title>ZeroClipboard.js TEST</title>
<meta charset="UTF-8" />
<style type="text/css">
section {
margin:1em auto;
font-size:16px;
}
@Korilakkuma
Korilakkuma / web-workers-inline.js
Last active August 29, 2015 14:07
Inline Web Workers
window.URL = window.URL || window.webkitURL;
var blob = new Blob(['self.onmessage = function(event) {var counter = 0 ; for (var i = 0, len = event.data; i < len; i++) {counter++;} self.postMessage(counter)};']);
var objectURL = window.URL.createObjectURL(blob);
var worker = new Worker(objectURL);
worker.onmessage = function(event) {
console.log(event.data);
window.URL.revokeObjectURL(blob);
@Korilakkuma
Korilakkuma / PencilTool.as
Last active August 29, 2015 14:07
Draw Application
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
public class PencilTool extends Sprite {
private var canvas:Sprite = null;
@Korilakkuma
Korilakkuma / MutexCounter.java
Last active August 29, 2015 14:07
synchronized statement
public final class MutexCounter {
private static final int NUM_LOAD = 10000;
private Object mutex = new Object();
private int count = 0;
private static class Worker implements Runnable {
private MutexCounter counter = null;
public Worker(MutexCounter counter) {
this.counter = counter;
@Korilakkuma
Korilakkuma / SynchronizedCounter.java
Last active August 29, 2015 14:07
synchronized method
public final class SynchronizedCounter {
private static final int NUM_LOAD = 10000;
private int count = 0;
private static class Worker implements Runnable {
private SynchronizedCounter counter = null;
public Worker(SynchronizedCounter counter) {
this.counter = counter;
}
@Korilakkuma
Korilakkuma / AtomicThread.java
Last active August 29, 2015 14:07
CAS (Compare And Swap)
import java.util.concurrent.atomic.*;
public final class AtomicThread {
private static final int NUM_LOAD = 100000;
private AtomicInteger count = new AtomicInteger();
private static class Worker implements Runnable {
private AtomicThread counter = null;
public Worker(AtomicThread counter) {
@Korilakkuma
Korilakkuma / ChatServer.java
Last active August 29, 2015 14:06
Chat Server
import java.util.*;
import java.io.*;
import java.net.*;
public final class ChatServer {
private static final int LISTEN_PORT = 9999;
private static final String TERMINAL_MESSAGE = "quit";
private static final int BUFFER_SIZE = 4096;
@Korilakkuma
Korilakkuma / ChatClient.java
Last active August 29, 2015 14:06
Chat Client
import java.io.*;
import java.net.*;
public final class ChatClient {
private static final String SERVER_HOST = "localhost";
private static final String TERMINAL_MESSAGE = "quit";
private static final int BUFFER_SIZE = 4096;
public static void main(String[] args) {
if (args.length < 1) {
@Korilakkuma
Korilakkuma / SocketServer.java
Last active August 29, 2015 14:06
Socket Server
import java.util.*;
import java.io.*;
import java.net.*;
public final class SocketServer {
private static final int LISTEN_PORT = 9999;
private static final int TIMEOUT = 60000; //ms
public static void main(String[] args) {
@Korilakkuma
Korilakkuma / SocketClient.java
Last active August 29, 2015 14:06
Socket Client
import java.io.*;
import java.net.*;
public final class SocketClient {
private static final String SERVER_HOST = "localhost";
private static final int SERVER_PORT = 9999;
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Require at least 1 argument !!");