Skip to content

Instantly share code, notes, and snippets.

@dangets
dangets / BasicRetrofitMoshiDemo.java
Last active September 25, 2023 19:39
Basic example of using Retrofit and Moshi
package com.dangets;
import com.squareup.moshi.Json;
import com.squareup.moshi.Moshi;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
@dangets
dangets / customer-events.avsc
Created June 28, 2018 15:14
Avro Union Types
[
{ "namespace": "com.dangets.customer",
"type": "record",
"name": "Address",
"fields": [
{"name": "receiver", "type": "string"},
{"name": "streetAddress", "type": "string"},
{"name": "addressLocality", "type": "string"},
{"name": "addressRegion", "type": "string"},
{"name": "postalCode", "type": "string"}
@dangets
dangets / FailRateLimiter.java
Created June 12, 2018 22:04
playing with jodah failesafe library
package com.dangets;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.TimeUnit;
import net.jodah.failsafe.CircuitBreaker;
public class FailRateLimiter {
public static void main(String[] args) throws InterruptedException, IOException {
@dangets
dangets / DropLastLinesReader.kt
Last active May 30, 2018 15:20
java.io.Reader that will drop n lines at end of other reader
package com.dangets
import java.io.IOException
import java.io.Reader
import kotlin.math.max
import kotlin.math.min
/**
* Create a Reader that will drop the last 'numLines' of input.
@dangets
dangets / KotlinMoshiDemo.kt
Last active August 15, 2021 19:13
kotlin moshi adapters demo
package com.dangets
import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonClass
import com.squareup.moshi.Moshi
import com.squareup.moshi.ToJson
import java.time.LocalDate
import java.util.*
data class Partition(val type: Type, val id: Int) {
@dangets
dangets / main.rs
Last active March 1, 2018 17:51
domain-modeling-made-functional rust and/or types
// OR types
#[derive(Debug, Copy, Clone, PartialEq)]
enum AppleVariety {
GoldenDelicious,
GrannySmith,
Fuji
}
#[derive(Debug, Copy, Clone, PartialEq)]
enum BananaVariety {
@dangets
dangets / index.html
Created May 16, 2013 17:30
simple d3.js histogram with specified threshold bins
<html>
<head>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
</head>
<body>
<svg id="viz">
</svg>
<script type="text/javascript">
var w = 500;
@dangets
dangets / thrust_opengl_interop.cu
Created June 13, 2012 20:46
Working cuda thrust opengl interop - original from NVIDIA SDK, then modified from deprecated ogl allocator thrust example
#include <math.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <cuda_gl_interop.h>
#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <thrust/iterator/counting_iterator.h>
@dangets
dangets / Particles.cu
Created June 7, 2012 19:42
CUDA Thrust Structure of Arrays reference as normal structure (non-working)
#include <iostream>
#include <cstdlib>
#include <thrust/iterator/zip_iterator.h>
using std::size_t;
template<typename Vector>
struct Particles {