Skip to content

Instantly share code, notes, and snippets.

View s-petersson's full-sized avatar

Simon Petersson s-petersson

View GitHub Profile
solveWithRepa :: (R.Array R.U R.DIM1 Int) -> IO (Int, Int, Int)
solveWithRepa stockPrices = do
let indices = R.fromListUnboxed (R.Z R.:. (8::Int)) [0..(S.size $ R.extent stockPrices)-1] :: R.Array R.U R.DIM1 Int
temp <- (R.computeP $ R.zipWith (\a b -> (a,b)) indices indices) :: IO(R.Array R.U R.DIM1 (Int, Int))
mapped <- (R.computeP $ R.zipWith (\(a,b) c -> (a,b,c)) temp indices) :: IO(R.Array R.U R.DIM1 (Int, Int, Int))
-- let temp = R.foldS foldF (0::Int, 0::Int, 0::Int) mapped
temp <- R.foldP foldF (0::Int, 0::Int, 0::Int) mapped
let (buyIdx, sellIdx, minIdx) = head $ R.toList temp
let buyAmount = stockPrices R.! (R.Z R.:. buyIdx)
@s-petersson
s-petersson / api-util.js
Last active March 7, 2018 00:43
Basic Redux Auth
export function configureFetch () {
const configuredFetch = (endpoint, options) => {
const initialOptions = {
headers: {
Authorization: Cookies.get('token')
}
}
const mergedOptions = _.merge(initialOptions, options);
import React from 'react';
import { Router, Link, useRoutes } from 'react-router';
import createHashHistory from 'history/lib/createHashHistory';
var pictures = [
{ id: 0, src: 'http://placekitten.com/601/601' },
{ id: 1, src: 'http://placekitten.com/610/610' },
{ id: 2, src: 'http://placekitten.com/620/620' }
];
function loginSuccess (router) {
return (dispatch, getState) => {
const state = getState();
console.log('test');
let nextPath = state.router.query ? state.router.query.next : '/home';
// TODO: Swap these two, when React 0.14 is released.
// dispatch(transitionTo(state.router.query.next));
router.transitionTo(nextPath);
};