Skip to content

Instantly share code, notes, and snippets.

# Simple web service that looks for an image metadata record on a MySQL db given its ID and sends it back in JSON
#
# Ruby 1.9.3
# All gems updated to the most recent version
# MBP i5 8gb Lion
#
# See source code above, combo is:
# Sinatra + Thin:
# - mysql_db.rb # mysql2 api class
# - sinatra_thin_server.rb
String[] stringArray = { "a", "b", "c", "d", "e" };
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(stringArray));
@epitron
epitron / activerecord-benchmarks.csv
Last active March 4, 2018 21:48
CockroachDB vs PostgreSQL vs MySQL vs SQLite
activerecord-cockroachdb activerecord-postgresql activerecord-mysql activerecord-sqlite Benchmark
9.216770* (60720k) 9.590111 (60984k) 12.455487 (69168k) 18.465701 (64944k) Model Object Creation: 3200 objects (No Transaction)
0.900417 (0k) 0.893337 (0k) 0.832904 (0k) 0.707108* (0k) Model Object Creation: 3200 objects (Transaction)
2.031437* (337128k) 2.070499 (336864k) 2.181665 (332112k) 2.215748 (333432k) Model Object Select: 6400 objects 64 times (No Transaction)
2.004822 (0k) 1.984105* (0k) 2.121498 (264k) 2.175031 (0k) Model Object Select: 6400 objects 64 times (Transaction)
3.460825 (0k) 3.337974 (0k) 3.875209 (0k) 2.622881* (0k) Model Object Select PK: 640 objects 64 times (No Transaction)
3.372082 (0k) 3.247312 (0k) 3.786783 (0k) 2.253132* (0k) Model Object Select PK: 640 objects 64 times (Transaction)
3.594136 (0k) 3.431209 (0k) 4.428752 (0k) 2.679963* (0k) Model Object Select Hash: 640 objects 64 times (No Transaction)
3.473371 (0k) 3.358583 (0k) 3.800874 (0k) 2.409768* (0k) Model Object Select Hash:
@jamesob
jamesob / nodejs-question.md
Last active January 26, 2019 22:50
An open question (rant) about node.js

Most developers would agree that, all other things being equal, a synchronous program is easier to work with than an asynchronous one. The logic for this is pretty clear: one flow of execution is easier for the human mind to simulate than n concurrent flows.

After doing two small projects in node.js (one of which is here -- ready for the blinding flurry of criticism), there's one question that I can't shake: if asynchronicity is an optimization (that is, a complexity introduced for the sake of performance), why would people, a priori, turn to a framework that imposes it for everything? If asynchronous code is harder to reason about, why would we elect to live in a world where it is the default?

It could be argued pretty well that the browser is a domain that inherently lends itself to an async model, but I'd be very curious to hear a defense of "async-first" thinking for problems that are typically solved on the server-side. When working with node, I've noticed

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
@alashow
alashow / OkHttp3Stack.java
Last active May 29, 2020 08:59 — forked from bryanstern/OkHttpStack.java
An OkHttp backed HttpStack for Volley (okhttp3 version)
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Circle Internet Financial
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@elwinar
elwinar / snake.go
Created November 18, 2014 11:30
ToSnake function for golang, convention-compliant
package main
import (
"unicode"
)
// ToSnake convert the given string to snake case following the Golang format:
// acronyms are converted to lower-case and preceded by an underscore.
func ToSnake(in string) string {
runes := []rune(in)
@emre
emre / golang_binary_search.go
Last active October 13, 2020 23:10
binary search implementation on golang slices
package main
import (
"fmt"
)
func BinarySearch(target_map []int, value int) int {
start_index := 0
end_index := len(target_map) - 1
@kustra
kustra / HeaderFooterRecyclerViewAdapter.java
Last active March 15, 2021 03:58 — forked from mheras/HeaderFooterRecyclerViewAdapter.java
Header & footer support for RecyclerView.Adapter, with custom ViewHolder types for the content, header and footer
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
public abstract class HeaderFooterRecyclerViewAdapter<
ContentViewHolder extends RecyclerView.ViewHolder,
HeaderViewHolder extends RecyclerView.ViewHolder,
FooterViewHolder extends RecyclerView.ViewHolder>
extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
/*
* Minimal classList shim for IE 9
* By Devon Govett
* MIT LICENSE
*/
if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function() {