Skip to content

Instantly share code, notes, and snippets.

Avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
@TheSeamau5
TheSeamau5 / eval_with_params.jl
Last active Nov 6, 2019
Evaluate a function with given parameters
View eval_with_params.jl
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,
View randomjog.elm
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
View mapreduce.elm
-- 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 Sep 25, 2016
N Queens in Python
View n_queens.py
#!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 Sep 20, 2016
Runner Generator (useful to generate different runners depending on the platform)
View makeRunner.js
// 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 Sep 20, 2016
Runner that takes an update and a render function and runs an app (optionally takes an observable)
View runner.js
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
Autosuggest with caching in Elm
View autosuggest.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 =
View powerset-string.elm
powerSet : String -> List String
powerSet =
String.words
>> List.foldr (\x acc -> acc ++ List.map ((::) x) acc) [[]]
>> List.map (String.join " ")
>> List.filter ((/=) "")
View separating-business-logic.elm
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 Apr 20, 2016
Make uniform distribution from 3 dice
View uniform-distribution-from-3-dice.elm
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 =