Skip to content

Instantly share code, notes, and snippets.

View duarten's full-sized avatar
🤷‍♂️

Duarte Nunes duarten

🤷‍♂️
View GitHub Profile
@duarten
duarten / CLQ.java
Created February 17, 2014 13:53
Benchmarking ConcurrentLinkedQueue
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CyclicBarrier;
import static java.lang.System.out;
public class CLQ {
public static final long WARMUP_ITERATIONS = 100L * 1000L;
public static final long ITERATIONS = 25L * 1000L * 1000L;
static private long[] consumptions;
#!/bin/bash
#
# Bash must have been compiled with this ability: --enable-net-redirections
# The device files below do not actually exist.
# Use /dev/udp for UDP sockets
exec 3<>/dev/tcp/host/port
# Write to the socket as with any file descriptor
echo "Write this to the socket" >&3
@duarten
duarten / BenchmarkIterateAndClear.java
Created July 27, 2014 14:49
Iterating and clearing
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;

Rich Hickey on becoming a better developer

Rich Hickey • 3 years ago

Sorry, I have to disagree with the entire premise here.

A wide variety of experiences might lead to well-roundedness, but not to greatness, nor even goodness. By constantly switching from one thing to another you are always reaching above your comfort zone, yes, but doing so by resetting your skill and knowledge level to zero.

Mastery comes from a combination of at least several of the following:

@duarten
duarten / agent.cpp
Created March 4, 2015 23:52
Java JVMTI Agent
#include <jvmti.h>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef struct {
jvmtiEnv *jvmti;
} GlobalAgentData;
@duarten
duarten / latency.txt
Last active August 29, 2015 14:17 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@duarten
duarten / vbr.s
Created May 14, 2015 14:27
A simple vbr
.equ START_OFFSET, 0x7c00
.equ STACK_TOP, START_OFFSET - 22
.equ VAR_BASE, START_OFFSET - 22
.equ DISK_ADDRESS_PACKET_OFFSET, 0
.equ PACKET_SIZE_OFFSET, 0
.equ SECTORS_TO_TRANSFER_OFFSET, 2
.equ TRANSFER_BUFFER_ADDR_OFFSET, 4
.equ TRANSFER_BUFFER_SEG_OFFSET, 6
.equ STARTING_SECTOR_OFFSET, 8
@duarten
duarten / AsyncLock.cs
Created February 8, 2011 00:54
A simple awaitable asynchronous lock
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
#pragma warning disable 420
public class AsyncLock
{
@duarten
duarten / AsyncExchanger.cs
Created February 9, 2011 22:15
An awaitable exchanger with timeout support
public class AsyncExchanger<T>
{
private ExchangerAwaiter _awaiter;
private class ExchangerAwaiter : IAwaiter<T>
{
private const int PENDING = 0;
private const int DONE = 1;
private const int TIMEOUT = 2;
@duarten
duarten / GetDuplicateAndMissing.cs
Created April 27, 2011 00:29
A solution to the mongoDB puzzle (http://goo.gl/A35lk)
//
// Given an array of N (can be very large) 64 bit integers where every integer 1-N
// appears once in the array, except there is one integer missing and one integer
// duplicated, find the missing and duplicated integers. The algorithm should run
// in linear time and in small constant space and leave the array untouched.
//
static void GetDuplicateAndMissing(long[] a, out long duplicate, out long missing)
{
long xor = 0; // duplicate ^ missing