Skip to content

Instantly share code, notes, and snippets.

Avatar

Steven Leiva StevenXL

View GitHub Profile
@StevenXL
StevenXL / maybe.elm
Created Apr 8, 2020
Elm - Simulating Maybe.map6
View maybe.elm
Maybe.map5
(\year month day hour minute ->
{ year = year
, month = month
, day = day
, hour = hour
, minute = minute
, second = 0
}
)
View yesod_haskell.md

Heroku Deployment

This tutorial will go over the steps needed in order to get a Yesod application deployed to Heroku, connecting to a database, and ensuring all requests are forced to use the SSL protocol.

We are going to assume two things in this tutorial:

  1. You have used Heroku before to deploy web applications.
  2. You have a Yesod application created with the yesod-postgres template.
View binarySearchFirstAndLast.js
function binarySearch(arr, k, searchType) {
let left = 0;
let right = arr.length - 1;
let ans = null;
while (left <= right) {
const midIdx = Math.floor((left + right) / 2);
const el = arr[midIdx];
@StevenXL
StevenXL / HelloSpec.hs
Last active Nov 11, 2019
Example integration of `hspec` and `persistent-sqlite`
View HelloSpec.hs
#!/usr/bin/env stack
-- stack --resolver lts-11.6 script
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
@StevenXL
StevenXL / web-fonts-asset-pipeline.md
Created Aug 13, 2019 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline
View web-fonts-asset-pipeline.md

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

View BespokeMonad.hs
{-# LANGUAGE InstanceSigs #-}
module Effects.BespokeMonad where
-- Log the value of the accumulator.
-- Pick an integer uniformly randomly from the half-open interval [0, 10).
-- Mutate the accumulator by adding the random integer to it.
-- We need an abstract data type
-- We need an execution fuction
-- We need helper functions
View gist:515f791db05cdf090e32861623eff9d3
- aeson
- aeson-casing
- aeson-iproute
- aeson-pretty
- aeson-typescript
- amazonka
- amazonka-core
- amazonka-s3
- amazonka-sqs
- async
@StevenXL
StevenXL / Test.hs
Created Apr 3, 2019
Compiler Error with Symbol
View Test.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
View cardinality.txt
| Either Bool (Bool, Maybe Bool -> Bool)| =
|Bool| + |(Bool, Maybe Bool -> Bool)| =
2 + |(Bool, Maybe Bool -> Bool)| =
2 + (|Bool| * |Maybe Bool -> Bool|) =
2 + (2 * |Maybe Bool -> Bool|) =
2 + (2 * |Bool|^(Maybe Bool)) =
2 + (2 * 2^(Maybe Bool)) =
2 + (2 * 2^(|Bool| + 1)) =
2 + (2 * 2^(2 + 1)) =
2 + (2 * 2^(3)) =
@StevenXL
StevenXL / Cipher.hs
Created Dec 21, 2018
Example usage of Scope Type Variables
View Cipher.hs
{-# LANGUAGE ScopedTypeVariables #-}
module Cipher where
data FourLetterAlphabet = L1 | L2 | L3 | L4 deriving (Show, Enum, Bounded)
-- Because of ScopedTypeVariables, the type variable "a" in the where clause
-- refers to the same type variable "a" as in the function's signature.
--
-- When we apply rotN to a value, all instances of "a" will be instantiated to
You can’t perform that action at this time.