Skip to content

Instantly share code, notes, and snippets.

View vyo's full-sized avatar
💜
Pony/JS/Lua

Manu Weidmann vyo

💜
Pony/JS/Lua
View GitHub Profile
public class Echo {
private String echo;
public Echo(String echo) {
this.echo = echo;
}
public String getEcho() {
return echo;
@vyo
vyo / typedValueFromJson.kt
Last active February 2, 2018 15:40
Kotlin type inference greatness
/**
* this little piece of magic provides some nice type inference info to the compiler
*
* courtesy of [StackOverflow](http://stackoverflow.com/a/33420043)
*/
inline fun <reified T> fromJSON(json: String): T = gson.fromJson<T>(json, object : TypeToken<T>() {}.type)
//usable as follows, and type inference doesn't even break a sweat
val project: Project = fromJSON(request.body())
val client = fromJSON<Client>(request.body())
@vyo
vyo / timedPromise.kt
Created December 17, 2016 14:32
Limit Kovenant promise by execution time
/**
* puts a time limit on the given [Promise]
* make sure to specify [Promise.fail] and/or [Promise.always] to be aware of the
* cancellation and be able to react accordingly
*
* @throws [IllegalArgumentException] if the given timeout is negative
*/
fun timedPromise(promise: Promise<Any, Exception>, millis: Long) {
if (millis < 0) {
@vyo
vyo / gist:b1966f25bbfcd3d919f7ffc558c541fe
Created June 23, 2016 16:03 — forked from jjb/gist:996292
How to securely acquire the Mozilla root certificate bundle for use with curl, Net::HTTP, etc.

If you want to use curl or net-http/open-uri to access https resources, you will often (always?) get an error, because they don't have the large number of root certificates installed that web browsers have.

You can manually install the root certs, but first you have to get them from somewhere. This article gives a nice description of how to do that. The source of the cert files it points to is hosted by the curl project, who kindly provide it in the .pem format.

problem: Sadly, ironically, and comically, it's not possible to access that file via https! Luckily, the awesome curl project does provide us with the script that they use to produce the file, so we can do it securely ourselves. Here's how.

  1. git clone https://github.com/bagder/curl.git
  2. cd curl/lib
  3. edit mk-ca-bundle.pl and change:
@vyo
vyo / pleasePromiseTest.js
Created March 14, 2016 20:53
short httpplease promise test
'use strict';
const httpplease = require('httpplease');
const httppleasePromise = require('httpplease-promises');
const Promise = require('bluebird');
const Please = httpplease.use(httppleasePromise(Promise));
Please.head('https://www.google.com')
.then(function (res) {
console.log(res.status);
@vyo
vyo / requestPromiseTest.js
Last active March 14, 2016 21:25
short request promise test
'use strict';
const RequestPromise = require('request-promise');
RequestPromise( {
uri: 'https://google.com',
method: 'HEAD',
resolveWithFullResponse: true,
simple: false
})
@vyo
vyo / docker-sync.txt
Created February 4, 2016 08:45
Docker: Sync with host time
$ date && docker run --rm -it -v /etc/localtime:/etc/localtime:ro alpine:3.3 date
Thu Feb 4 09:46:54 CET 2016
Thu Feb 4 09:46:55 CET 2016