Skip to content

Instantly share code, notes, and snippets.

David Eriksson twogood

Block or report user

Report or block twogood

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@twogood
twogood / DaggerViewModelFactory.kt
Created Jan 25, 2019
Android Jetpack ViewModel, Dagger 2, Kotlin coroutines
View DaggerViewModelFactory.kt
package example
import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProvider
import dagger.Binds
import dagger.MapKey
import dagger.Module
import javax.inject.Inject
import javax.inject.Provider
import kotlin.reflect.KClass
@twogood
twogood / transformAsyncPair.kt
Created Nov 14, 2017
Create ListenableFuture<Pair<A, B>> from ListenableFuture<A> and ListenableFuture<B>
View transformAsyncPair.kt
fun <A, B> transformAsyncPair(futureA: ListenableFuture<A>, futureB: ListenableFuture<B>, executor: Executor): ListenableFuture<Pair<A, B>> {
return Futures.transformAsync(futureA, AsyncFunction<A, Pair<A, B>> { a ->
Futures.transformAsync(futureB, AsyncFunction<B, Pair<A, B>> { b ->
Futures.immediateFuture(Pair<A, B>(a!!, b!!))
}, executor)
}, executor)
}
@twogood
twogood / studio.sh
Created Oct 20, 2017
Android studio 3 beta fix
View studio.sh
LC_NUMERIC="en_US.UTF-8"
@twogood
twogood / LocalDateColumnMapper.java
Created Jun 13, 2017
Using LocalDate fields with BeanMapper in JDBI
View LocalDateColumnMapper.java
//
// USAGE:
//
// jdbi.registerColumnMapper(new LocalDateColumnMapper());
//
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDate;
@twogood
twogood / LocalDateArgumentFactory.java
Created Jun 13, 2017
ArgumentFactory to support LocalDate with @BindBean in JDBI
View LocalDateArgumentFactory.java
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.time.LocalDate;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.Argument;
import org.skife.jdbi.v2.tweak.ArgumentFactory;
View AsyncTaskResult.java
package com.claimtowers.common.asynctask;
public class AsyncTaskResult<T> {
private T result;
private Exception exception;
public AsyncTaskResult(T result) {
this.result = result;
}
View sendgrid-webhook.js
var express = require('express');
var multer = require('multer');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
});
app.post('/parse', multer().any(), function (req, res) {
var from = req.body.from;
@twogood
twogood / Secure Sessions Howto
Created Feb 23, 2016 — forked from nikmartin/Secure Sessions Howto
Secure sessions with Node.js, Connect, and Nginx as an SSL Proxy
View Secure Sessions Howto
Secure sessions are easy, but it's not very well documented, so I'm changing that.
Here's a recipe for secure sessions in Node.js when NginX is used as an SSL proxy:
The desired configuration for using NginX as an SSL proxy is to offload SSL processing
and to put a hardened web server in front of your Node.js application, like:
[NODE.JS APP] <- HTTP -> [NginX] <- HTTPS -> [CLIENT]
To do this, here's what you need to do:
View python-compile.sh
python -m py_compile script.py
@twogood
twogood / counter.js
Created May 28, 2015
Code of the day
View counter.js
function counter(colAdd, rowAdd) {
var count = 1;
var x, y;
for (x = move.col + colAdd, y = move.row + rowAdd;
isOwnedByCurrentPlayer(x, y);
count++, x += colAdd, y += rowAdd) {
}
for (x = move.col - colAdd, y = move.row - rowAdd;
isOwnedByCurrentPlayer(x, y);
count++, x -= colAdd, y -= rowAdd) {
You can’t perform that action at this time.