Skip to content

Instantly share code, notes, and snippets.

View elliotdavies's full-sized avatar

Elliot Davies elliotdavies

View GitHub Profile
@elliotdavies
elliotdavies / bundle.js
Created August 10, 2019 15:18
PureScript async imports
var PS = {};
// Either need to rename FFI modules (e.g. `$PS["Effect.Console.FFI"]`) or else
// combine them as shown here to avoid recursive promise calls
(function($PS) {
$PS["Effect.Console"] = $PS["Effect.Console"] || Promise.resolve({});
$PS["Effect.Console"] = $PS["Effect.Console"].then(exports => {
exports["log"] = function(s) {
return function() {
console.log(s);
# FizzBuzz
Write a program that prints the numbers from 1 to 100, except:
- For multiples of 3, print "Fizz" instead of the number
- For multiples of 5, print "Buzz" instead of the number
- For multiples of both 3 and 5, print "FizzBuzz" instead of the number
## Extension
# DNA sequences
You're working in a scientific laboratory that specialises in DNA research. Cool!
Each sequence of DNA is made up of four bases: A, C, G and T. Your job is to count how many times each base appears in a particular sequence. You quickly get bored of doing this by hand and decide to write a program to do it for you.
You have the following sequence:
`"GCAACTCTCTATTGTGCCGGAAGTTAATATGCAAAGAGTAATTTCCCATCCCCACTACCGAATCCCTGACCAACCGCCTTCTTCAGGGTGATTACGTGCTAAGCTTATTAGCGCTCTCTTTTCCGATTCACTGTTCAAGATCGTCATTTTCGGGACCATTCCTTGATTCACACACTGAACGATTATGAGGTGTATACGAAACGGGTAGAGGCCCGCAAATGCGTCCTCGATACAGATGCTCGGGTCTGTTCCTGCACGGGCACGTAAACAGCGTGTTAAGGGAGAAAGTGTGAGTGTGAAGATGAATTAAAGGCTTATCAGCCACGGCTTCAAAGACTATAGCAACGCAGAGGAACCGAGCATTTCCATCCCAGCTCATGGTAATTTACTACGGGAGCTAACGCCAGAGGTAATATTTCTG TCTGGCAGGTTTTATTAGCCGGGTGGGAGGGAGGAAGGAGTTGAAACTCGTTACCCAATTACTCGAAGGTGTACTATTACTTCTTTGGAGATCAACTGCAGTTTGCTTGGTAACACTCACATATAAATTGTGTACTGGGTCCCATTACTTTTTCTAGGGAGTAATTAAGTTATCCCTTAGCGAATATGATGCGGCTTTGGCTTTTGGCTTAACTACCCGAAAACCAGT
# String matrices
You're working on a piece of code that deals with matrices of numbers. Unfortunately, you have to integrate with a legacy system that gives you the matrices as strings.
The legacy system gives you some strings like so:
`1,2,3 4,5,6 7,8,9`
All rows are guaranteed to be the same length (you don't have to check for this) and are separated by spaces. Numbers in a row do _not_ have spaces between them and are separated by commas.
# School years
You're helping your school design a new admin system. You've been given a list of students' names along with their school year. The data looks like so:
Name | Year
--------|-----
Amy | 1
Bob | 3
Charlie | 2
@elliotdavies
elliotdavies / react-ref-example.purs
Created April 24, 2019 13:07
WIP example for `purescript-react` createRef
import React as React
import React.DOM as DOM
import React.DOM.Props as Props
import React.SyntheticEvent (currentTarget)
import Web.HTML.HTMLElement (focus)
import Unsafe.Coerce (unsafeCoerce)
type MyState
@elliotdavies
elliotdavies / test.hs
Created October 10, 2017 20:20
Haskell pattern question
-- In `f` we want to keep piping (part of) the result of one function into
-- another, and stop as soon as something fails
f :: [A] -> Either String (B, [A])
f xs =
case f1 xs of
Left s -> Left s
Right (res1, xs') ->
case f2 xs' of
Left s -> Left s
Right (res2, xs'') ->
@elliotdavies
elliotdavies / fabfour.scss
Created November 4, 2016 16:29
SASS mixin for the 'Fab Four' responsive email design technique
// Fab Four technique: https://medium.freecodecamp.com/the-fab-four-technique-to-create-responsive-emails-without-media-queries-baf11fdfa848#.65xejb13e
// (Credit to Rémi Parmentier)
// This SASS mixin can be applied to each responsive block
// The parent container of such blocks will want to use `font-size: 0;` to avoid inline-block spacing issues
@mixin responsive ($mobilePc, $desktopPc, $desktopAbs, $bp: 660, $neg: false) {
display: inline-block;
vertical-align: top;
// Mobile size as a %