Skip to content

Instantly share code, notes, and snippets.

@OlavHN
OlavHN / vote.py
Created January 16, 2018 08:48
Propagate votes example
from scipy import sparse
class Proposition:
def __init__(self, title):
self.title = title
self.votes = {}
self.delegations = {}
def vote(self, user, vote):
@OlavHN
OlavHN / hierarchical_test.py
Last active November 17, 2017 11:57
Example of hierarchical categories with ids managed by tensorflow
import tensorflow as tf
def example():
leafs = tf.contrib.lookup.index_table_from_file(
vocabulary_file='leafs.txt')
parents = tf.contrib.lookup.index_table_from_file(
vocabulary_file='parents.txt')
leafs2parents = tf.contrib.lookup.index_to_string_table_from_file(
vocabulary_file='leaf2parents.txt')
@OlavHN
OlavHN / gist:ff73b104bb25e5e08a51
Last active June 28, 2017 19:27
React render to polymer components!
<!doctype html>
<html>
<head>
<!-- Web Component Polyfill for old browsers -->
<script src="https://www.polymer-project.org/platform.js"></script>
<!-- Release candidate of next React -->
<script src="http://fb.me/react-with-addons-0.12.0-rc1.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.0-rc1.js"></script>
<!-- Import a web component -->
@OlavHN
OlavHN / logger.js
Created March 29, 2016 10:05
redux middleware with firebase replay / remote actions
import Firebase from 'firebase';
const firebaseUrl = 'https://spatially.firebaseio.com/clients';
const timeOffsetUrl = 'https://spatially.firebaseio.com/.info/serverTimeOffset';
let ref = new Firebase(firebaseUrl);
let timeRef = new Firebase(timeOffsetUrl);
let cachedUid;
export default ({dispatch, getState}) => next => action => {
// The first action rehydrates, so now we've probably got the uid now
@OlavHN
OlavHN / test.js
Created August 1, 2016 10:11
Inject tabs template
import React, {Component, PropTypes} from 'react';
import {Tabs, Tab} from 'material-ui/Tabs';
class MyAwesomeTabTemplate extends Component {
static propTypes = {
children: PropTypes.node,
selected: PropTypes.bool,
};
render() {
'use strict';
let firebase = require('firebase');
let fs = require('fs');
let spawn = require('child_process').spawn;
let throttle = require('lodash.throttle');
let request = require('superagent');
let AWS = require('aws-sdk');
let ref = new Firebase('https://neural.firebaseio.com/');
@OlavHN
OlavHN / gist:7427620
Created November 12, 2013 08:45
Type checking in javascript!
function type_checker() {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
function getParamNames(func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
var result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(/([^\s,]+)/g);
if(result === null)
result = [];
return result;
}
return function(types, func) {
From 0d54f904cebce9cad031af8e5dd6b040d3f314f3 Mon Sep 17 00:00:00 2001
From: Olav Nymoen <olav@comoyo.com>
Date: Fri, 23 Aug 2013 11:40:57 +0200
Subject: [PATCH] testing datastores
---
apps/test/index.html | 2 ++
apps/test/manifest.webapp | 26 ++++++++++++++++++++++++++
apps/test/source.js | 7 +++++++
3 files changed, 35 insertions(+)
{
"name": "testee",
"description": "testing app",
"type": "certified",
"launch_path": "/index.html",
"developer": {
"name": "The Gaia Team",
"url": "https://github.com/mozilla-b2g/gaia"
},
"datastores-owned": {
@OlavHN
OlavHN / keyboard.css
Created January 9, 2013 15:07
Files: apps/keyboard/style/keyboard.css apps/keyboard/js/render.js 1. Open Contacts 2. Click Mobile -> Phone 3. Hold down button with alt key I expected it to be a highlighted alternative, but it turns out to render the key above the highlighting or something similar.
/* Media definitions */
@media screen and (max--moz-device-pixel-ratio: 1.5) {
html {
font-size: 15px;
}
}
@font-face {
font-family: 'Keyboard Symbols';
font-weight: 600;