This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func double[T int | float64](x T) T { | |
return T(2) * x | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const items = [4,8,0,3,1,5,7,2,6,9]; | |
console.log(items); | |
quicksort<number>(items); | |
console.log(items); | |
export function quicksort<T>(items: T[]): void { | |
quicksortSub(items, 0, items.length-1); | |
} | |
function quicksortSub<T>(items: T[], lo: number, hi: number) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
void *entry_point_0(void * input) { | |
printf("Thread 0 started\n"); | |
sleep(10); | |
printf("Thread 0 finished\n"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# display tree of json key names | |
# like tree(1) for JSON | |
# by @tlehman | |
require 'json' | |
input = STDIN.read || File.open(ARGV.first).read | |
parsed_input = JSON.parse(input) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Units in C++ with user-defined literals | |
// g++ units.cpp -std=c++11 && ./a.out | |
#include <assert.h> | |
#include <iostream> | |
using namespace std; | |
long double operator "" _km(long double x) { | |
return 0.6213725 * x; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Chapter 2 of "Elements of Programming": Transformations | |
*/ | |
#define DistanceType(F) int | |
#define Domain(F) int | |
#define pointer(T) *T | |
template<typename T> | |
class Transformation { | |
public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.Builder; | |
import lombok.Value; | |
@Builder | |
@Value | |
public class Address { | |
private String street1; | |
private String street2; | |
private String city; | |
private String cityCode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AddTwo { | |
public static void main(String args[]) { | |
int c = add(2,3); | |
} | |
public static int add(int a, int b) { | |
return a + b; | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tobilehman.benchmarks; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Random; | |
public class StreamMax { | |
public static void main(String args[]) { | |
StreamMax sm = new StreamMax(10_000_000); | |
Long then,now; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tobilehman.benchmarks; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Random; | |
public class StreamMax { | |
public static void main(String args[]) { | |
StreamMax sm = new StreamMax(10_000_000); | |
Long then,now; |