Skip to content

Instantly share code, notes, and snippets.

View taichi's full-sized avatar
😸
shaving...

taichi taichi

😸
shaving...
View GitHub Profile
@taichi
taichi / Rx.java
Last active August 29, 2015 14:00
起動引数として受け取ったURLを短縮して標準出力し、その短縮したURLに対するリダイレクトを提供するサーバをエラー処理しないことで、どれだけ短く書けるかという遊び。言語に付随する標準APIのみを利用して実装すること。
public class Rx {
public static void main(String[] args) throws Exception {
rx.Observable.from(args)
.map(s -> java.util.Arrays.asList(Integer.toHexString( s.hashCode()), s))
.reduce(com.sun.net.httpserver.HttpServer.create(new java.net.InetSocketAddress(8080), 0), (s, e) -> {
System.out.printf("http://localhost:%d/%s -> %s%n",s.getAddress().getPort(), e.get(0), e.get(1));
return s.createContext("/" + e.get(0), ctx -> {
ctx.getResponseHeaders().add("Location", e.get(1));
ctx.sendResponseHeaders(302, 0);
ctx.close();
require 'gson'
module Yajl
class Parser
attr_accessor :on_parse_complete
def initialize
@delegate = Gson::Decoder.new
@reader, @writer = IO.pipe
end

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

static ObsoleteFlag obsolete_jvm_flags[] = {
{ "UseTrainGC", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "UseSpecialLargeObjectHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "UseOversizedCarHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "TraceCarAllocation", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "PrintTrainGCProcessingStats", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "LogOfCarSpaceSize", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "OversizedCarThreshold", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "MinTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "DefaultTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
// Support for concurrent collection policy decisions.
bool CompactibleFreeListSpace::should_concurrent_collect() const {
// In the future we might want to add in frgamentation stats --
// including erosion of the "mountain" into this decision as well.
return !adaptive_freelists() && linearAllocationWouldFail();
}
bool CompactibleFreeListSpace::linearAllocationWouldFail() const {
return _smallLinearAllocBlock._word_size == 0;
}
void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) {
uintx region_size = G1HeapRegionSize;
if (FLAG_IS_DEFAULT(G1HeapRegionSize)) {
size_t average_heap_size = (initial_heap_size + max_heap_size) / 2;
region_size = MAX2(average_heap_size / TARGET_REGION_NUMBER,
(uintx) MIN_REGION_SIZE);
}
int region_size_log = log2_long((jlong) region_size);
// Recalculate the region size to make sure it's a power of
package de.am.gc.benchmarks;
import java.util.ArrayList;
import java.util.List;
/**
* GC benchmark producing a mix of lifetime=0 and lifetime>0 objects which are kept in randomly updated lists.
*
* @author jsound
*/
void VM_Version::get_processor_features() {
_cpu = 4; // 486 by default
_model = 0;
_stepping = 0;
_cpuFeatures = 0;
_logical_processors_per_package = 1;
if (!Use486InstrsOnly) {
// Get raw processor info
@taichi
taichi / win32.c
Last active August 29, 2015 14:04
static int
winnt_stat(const WCHAR *path, struct stati64 *st)
{
HANDLE h;
WIN32_FIND_DATAW wfd;
WIN32_FILE_ATTRIBUTE_DATA wfa;
const WCHAR *p = path;
memset(st, 0, sizeof(*st));
st->st_nlink = 1;
@taichi
taichi / pgradle.bat
Created July 17, 2014 01:09
gradle task selection with peco on windows.
@echo off
for /f %%i in ('gradlew tasks ^| peco') do (
echo gradlew %%i
gradlew %%i
break
)