Skip to content

Instantly share code, notes, and snippets.

@kosta
kosta / gist:6a17365c71ca88031740
Last active August 29, 2015 14:23
Empty Win32 MessageBox using rust no_std
This generates a win 32bit exe with of ~48 KB (~35 KB after upx compression). Tested with rust nightly of May 16th 2015
https://static.rust-lang.org/dist/2015-05-16/rust-nightly-i686-pc-windows-gnu.msi
Command line:
cargo clean && cargo build -v --release
Cargo.toml:
[package]
name = "msgbox"
version = "0.1.0"
@kosta
kosta / inout.java
Created March 26, 2014 06:47
Copy stdin to stdout in Java
import java.io.IOException;
/**
* Class that copies stdin to stdout, as compained about as not being cleanly
* writable in Java on Hacker News.
* In real code, you would just write IOUtils.copy(System.in, System.out),
* which does basically the same thing.
* This does not catch any exceptions as a) this is just an "exercise" and
* b) all we could do with them is pretty-print them. So let the runtime
* print them for you.
@kosta
kosta / TypeErasureIsReallyWeird.java
Created November 8, 2011 09:58
Type erasure in java
class TypeErasureIsReallyWeird {
private static class AndNowWithGenerics<LongActually> {
LongActually UhOh(Object o) {
try {
@SuppressWarnings("unchecked")
LongActually longish = (LongActually) o;
System.out.println(
"In a generic class, casting String to Long seems ok. Long value is: " +
longish);
@kosta
kosta / gist:1015232
Created June 8, 2011 19:55
Small tcp server
package main
import (
"fmt"
"net"
"bufio"
"sync"
"os/signal"
)