Skip to content

Instantly share code, notes, and snippets.

View abiodun0's full-sized avatar

Abiodun abiodun0

View GitHub Profile
@abiodun0
abiodun0 / some_func.js
Last active February 8, 2021 21:03
Testing adhoc
function getGithubURL(resource) {
return `https://github.com/${resource}`;
}
function updateStoryViewWidth() {
const storyViewElem = document.querySelector('.story-view');
const { height } = storyViewElem.getBoundingClientRect();
storyViewElem.style.width = `${height / 1.77}px`;
}
@abiodun0
abiodun0 / algebra.hs
Created September 20, 2020 03:15
Fixed point algebras (To be Updated)
-- Algebra gives the ability to perform calculaitons with number and symbols
-- algebra treat symbols as elements of a vector space, multiplied by scalar quantity and added to each other
type Algebra f a = f a -> a
type SimpleA = Algebra ExprF Int
data ExprF a = Cons Int
| Add a a
| Mul a a
@abiodun0
abiodun0 / abitrefactoring.js
Last active August 22, 2020 08:03
Heap, max heap and heap sort,merge and quck sort
function heapify(arr, i) {
let [index, left, right] = [i, i*2+1, i*2+2]
if(arr[left] && arr[left] > arr[i]) {
index = left
}
if(arr[right] && arr[right] > arr[index]) {
index = right
}
if(index !== i) {
let temp = arr[i]
@abiodun0
abiodun0 / comonadsmonoidsandtrees.js
Created July 23, 2020 07:46
commonads, monoids and trees
// Leaf : val -> ann -> Tree val ann
function Leaf(val, ann) {
return {
ann: ann,
val: val,
toString: () => `Leaf(${val}, ${ann})`,
map: f => Leaf(val, f(ann)),
extend: f => Leaf(val, f(Leaf(val, ann))),
reduce: (f, acc) => f(acc, ann),
};
@abiodun0
abiodun0 / fibwithmonodis.hs
Created July 17, 2020 14:32
Fib with monodis, 25 days back
-- Matrices multiplication are associative by default, hence the use of semigroup and monoids in this case
import Data.Semigroup
data Matrix2x2 = Matrix
{ x00 :: Integer, x01 :: Integer
, x10 :: Integer, x11 :: Integer
}
instance Monoid Matrix2x2 where
@abiodun0
abiodun0 / todo.js
Created October 9, 2019 17:04
Just another one really
import React from 'react'
import { render } from 'react-dom';
import { createStore, combineReducers } from 'redux'
import { compose, map, prop, pipe, curry, reduce, propOr, identity, add, pluck, max, reject,propEq} from 'ramda'
const combine = curry((g, c) => x => (<div>{g(x)} {c(x)} </div>));
const combineComonents = (...args) => {
const [first, ...rest] = args;
return reduce((acc, c) => combine(acc, c), first, rest);
}
@abiodun0
abiodun0 / view_and_reader_monad.js
Last active September 16, 2021 04:10
React and reader monad from first principles https://codesandbox.io/s/react-composition-rjmzd
import ReactDOM from 'react-dom'
import Reac, { createElement } from 'react'
import { compose, map, ap, pipe } from 'ramda'
import IntlMessageFormat from 'intl-messageformat'
const copyrightNotice = View(({ author, year }) => <p>© {author} {year}</p>)
const Monad = {
do: gen => {
// check this out; with the static land approach of modeling instances as values,
// you can actually witness functor instances for the classes themselves.
// this gives you instances for free when you have structure preserving morphisms from a
// type that has some instance to a type for which you want that instance:
const { adt, match } = require("@masaeedu/adt")
// :: type Eq v = { equals: v -> v -> Boolean }
// :: type Contravariant f = { contramap: (b -> a) -> f a -> f b }

The use of units is ubiquitous in science. Physics uses units to distinguish distance (e.g., meters, kilometers, etc.), weight (e.g., kilograms, grams), and many other quantities. Computer scientists have specialized units to describe storage capacity (e.g., kilobytes, megabytes, etc.). You are to write a program to display the conversion factors for a set of units.

Specifying the relationship between various units can be done in many different, but equivalent, ways. For example, the units for metric distance can be specified as the group of relationships between pairs for units: 1 km = 1000 m, 1 m = 100 cm, and 1 cm = 10 mm. An alternative set of pairs consists of: 1 km = 100000 cm, 1 km = 1000000 mm, and 1 m = 1000 mm. In either presentation, the same relationship can be inferred: 1 km = 1000 m = 100000 cm = 1000000 mm.

For this problem, the units are to be sorted according to their descending size. For example, among the length units cm, km, m, mm, km is considered the biggest unit since 1 km corresponds

@abiodun0
abiodun0 / cons.swift
Last active July 1, 2020 00:41
cons car and cdr in swift
typealias LinkedList = ((Any, Any) -> Any) -> Any
typealias Cons = (Any, Any) -> LinkedList
typealias Result = (LinkedList) -> Any
let cons: Cons = { (x: Any, y: Any) in
{
(z: (Any, Any) -> Any) in z(x, y)
}
}