Skip to content

Instantly share code, notes, and snippets.

View roosmaa's full-sized avatar

Mart Roosmaa roosmaa

  • Madrid, Spain
View GitHub Profile
@roosmaa
roosmaa / .travis.yml
Created September 15, 2015 21:13
Speed up Docker builds on TravisCI by reusing dependency containers
language: python
python:
- "2.7"
sudo: required
services:
- docker
install:
- $TRAVIS_BUILD_DIR/build-containers.py
script:
- docker run --rm my-app test
@roosmaa
roosmaa / main.rs
Created September 15, 2015 20:27
Dynamic method invocation in Rust
#![feature(plugin)]
#![plugin(dynamic_gen)]
extern crate dynamic;
use dynamic::Object;
#[protocol]
trait Pet {
fn speak(&self) -> String;
}
@roosmaa
roosmaa / main.rs
Created August 19, 2015 21:11
Composing and using enums from different modules in Rust
// This is an attempt to figure out a way to compose and use enums
// from different modules interchangebly. Main use-case would be
// when enums are used for messaging.
mod event {
pub trait AnEvent<T> {
fn make(T) -> Self;
fn get(self) -> Option<T>;
}
}
@roosmaa
roosmaa / clef_login.go
Created March 27, 2015 08:17
Clef login in Go
package main
import (
"encoding/json"
"fmt"
"golang.org/x/oauth2"
)
func main() {
code := "code"
Verifying that +roosmaa is my openname (Bitcoin username). https://onename.com/roosmaa
### Keybase proof
I hereby claim:
* I am roosmaa on github.
* I am mart (https://keybase.io/mart) on keybase.
* I have a public key whose fingerprint is 25E3 6A82 74D1 E1C6 656E 2A3D F762 474B 1635 4473
To claim this, I am signing this object:
@roosmaa
roosmaa / Facebook.Session.cs
Created December 27, 2012 16:25
Twice defined static helper variable
// ... (line: 410)
static IntPtr id_setPermissions_Ljava_util_List_;
[Register ("setPermissions", "(Ljava/util/List;)Lcom/facebook/Session$AuthorizationRequest;", "")]
public global::Facebook.Session.AuthorizationRequest SetPermissions (global::System.Collections.IList p0)
{
if (id_setPermissions_Ljava_util_List_ == IntPtr.Zero)
id_setPermissions_Ljava_util_List_ = JNIEnv.GetMethodID (class_ref, "setPermissions", "(Ljava/util/List;)Lcom/facebook/Session$AuthorizationRequest;");
IntPtr native_p0 = global::Android.Runtime.JavaList.ToLocalJniHandle (p0);
global::Facebook.Session.AuthorizationRequest __ret = global::Java.Lang.Object.GetObject<global::Facebook.Session.AuthorizationRequest> (JNIEnv.CallObjectMethod (Handle, id_setPermissions_Ljava_util_List_, new JValue (native_p0)), JniHandleOwnership.TransferLocalRef);
JNIEnv.DeleteLocalRef (native_p0);
@roosmaa
roosmaa / Sample.java
Created July 4, 2012 07:29
Dynamically registered BroadcastReceivers pattern
package net.roosmaa.example;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
public class Sample
{
private Context mContext;
@roosmaa
roosmaa / c2dm.py
Created May 11, 2012 21:49
Using the refresh token to obtain the access token from Google OAuth 2.0 server
import logging
import urllib
import urllib2
import json
log = logging.getLogger(__name__)
def authenticate(refresh_token, client_id, client_secret):
"""Authenticates with the Google servers to get authentication token
for C2DM API calls.
@roosmaa
roosmaa / jwt.py
Created May 5, 2012 17:37
Simple JWT (JSON Web Token) generator for Google OAuth 2.0 service (Server to Server) authentication
import base64
import time
import OpenSSL
from django.utils import simplejson
def _json_dumps(obj):
return simplejson.dumps(obj, separators=(',', ':'))
def _base64url(data):