Skip to content

Instantly share code, notes, and snippets.

@OlavHN
OlavHN / vote.py
Created Jan 16, 2018
Propagate votes example
View vote.py
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 Nov 17, 2017
Example of hierarchical categories with ids managed by tensorflow
View hierarchical_test.py
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 Aug 1, 2016
Inject tabs template
View test.js
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() {
View neuralstyle.js
'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 Mar 29, 2016
redux middleware with firebase replay / remote actions
View logger.js
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
View gist:158edfc85c74213d6e3d
// 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 &&
View gameoflife
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 Aug 29, 2015
Drag to animation
View Header.jsx
'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 Jun 28, 2017
React render to polymer components!
View gist:ff73b104bb25e5e08a51
<!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 -->
View gist:982bce14f7ecbceba967
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}>