Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
@TheSeamau5
TheSeamau5 / eval_with_params.jl
Last active November 6, 2019 11:01
Evaluate a function with given parameters
macro eval_with_params(expr, params...)
# Put the params before the expression
expr_with_params = [collect(params)..., expr]
# Wrap the expressions in :block Expressions
Expr(:block, expr_with_params...)
end
@eval_with_params(
x + y,
import Html exposing (Html, div, text, button)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import Random exposing (Seed, initialSeed, step, float, bool)
-- Start with initial probability
-- For every miss :
-- p = p * 0.9
-- Goal: In point-free style
mapReduce : (a -> b) -> (List b -> c) -> List a -> c
-- Simple
mapReduce mapper reducer list
= reducer (List.map mapper list)
-- Remove the last argument via composition
mapReduce mapper reducer
= reducer << List.map mapper
@TheSeamau5
TheSeamau5 / n_queens.py
Created September 25, 2016 23:41
N Queens in Python
#!usr/bin/python
from itertools import permutations
def n_queens(n):
cols = range(n)
for vec in permutations(cols):
if n == len(set(vec[i] + i for i in cols)) and n == len(set(vec[i] - i for i in cols)):
print("\n".join('.' * i + 'Q' + '.' * (n - i - 1) for i in vec) + "\n===\n")
@TheSeamau5
TheSeamau5 / makeRunner.js
Last active September 20, 2016 04:25
Runner Generator (useful to generate different runners depending on the platform)
// makeRunner : (renderer : ReactComponent -> ())
// -> (update : s -> a -> s, render : s -> Dispatcher a -> ReactComponent, observable : Observable a)
// -> ()
export const makeRunner = (renderer) => (update, render, observable) => {
const store = createStore(update);
const renderApp = () => renderer(render(store.getState(), store.dispatch));
renderApp();
@TheSeamau5
TheSeamau5 / runner.js
Created September 20, 2016 04:14
Runner that takes an update and a render function and runs an app (optionally takes an observable)
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { createStore } from 'redux';
import Rx from 'rx';
// run : (update: s -> a -> s, render: s -> Dispatcher a -> Html, observable: Observable a, root: String)
export const run = (update, render, observable, root='root') => {
const store = createStore(update);
const renderApp = () => {
@TheSeamau5
TheSeamau5 / autosuggest.elm
Created May 16, 2016 07:11
Autosuggest with caching in Elm
import Dict exposing (Dict)
import Html exposing (Html, div, text, input, ul, li)
import Html.App as Html
import Html.Events exposing (..)
import Task exposing (Task)
import String
---------------------------
main =
powerSet : String -> List String
powerSet =
String.words
>> List.foldr (\x acc -> acc ++ List.map ((::) x) acc) [[]]
>> List.map (String.join " ")
>> List.filter ((/=) "")
import Signal exposing (Address)
import Html exposing (Html, button, text, div)
import Html.Events exposing (onClick)
import StartApp.Simple as StartApp exposing (start)
type alias State =
{ counter : Int }
@TheSeamau5
TheSeamau5 / uniform-distribution-from-3-dice.elm
Created April 20, 2016 00:49
Make uniform distribution from 3 dice
import Random exposing (Generator, Seed)
import Signal exposing (Signal)
import Graphics.Element exposing (Element, show, flow, down)
import Time exposing (Time)
import String
import List
die : Generator Int
die =