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 / 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 / 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
// known mcc/mnc values for our sim card (this is Telenor Norway)
var mcc = 242;
var mnc = 01;
// First get the sim card number (API supports multi sim phones)
var simNum = Array.slice(window.navigator.mozMobileConnections)
.reduce(function(current, connection, i) {
if (connection && connection.data && connection.data.network) {
// For ONCE we're actually using type coercion as it's meant here!
if (connection.data.network.mcc == mcc &&
function gameoflife(matrix) {
var population = [];
for (var i = 0; i < matrix.length; i++) {
population[i] = [];
for (var j = 0; j < matrix[0].length; j++)
population[i][j] = 0;
}
matrix.forEach(function(row, i) {
row.forEach(function(col, j) {
@OlavHN
OlavHN / Header.jsx
Last active August 29, 2015 14:11
Drag to animation
'use strict';
var React = require('react');
var RCSS = require('rcss');
var tweenState = require('react-tween-state');
var DragMixin = require('./mixins/drag-mixin');
var headerStyle = RCSS.registerClass({
position: 'relative',
width: '100%',
@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 -->
var Summary1 = React.createClass({
render: function(() {
var cards = this.props.cards
return (
<div>
<Notification />
<div>
cards.map(function(card, i) {
return <Card key={'key' + i} data={card}>