Skip to content

Instantly share code, notes, and snippets.

@ronanyeah
ronanyeah / App.purs
Created August 8, 2018 00:26
Psc server
app ::
Rf.Ref (Object Chat) ->
Rf.Ref (Object Unit) ->
Request ->
Response ->
Effect Unit
app chats sockets req res = do
setHeader res "Access-Control-Allow-Origin" "*"
let outputStream = responseAsStream res
let method = requestMethod req
scrollToCurrentYear : Cmd Msg
scrollToCurrentYear =
Process.sleep 100
|> Task.andThen (always Time.now)
|> Task.andThen
(Time.toYear Time.utc
>> String.fromInt
>> Dom.getElement
)
|> Task.andThen

In ~/.bash_aliases:

alias dev='env $(cat dev.env | xargs)'
alias prod='env $(cat prod.env | xargs)'

Put environment variables in dev.env, prod.env etc

@ronanyeah
ronanyeah / panes.sh
Created June 14, 2019 14:24
Tmux pane setup
#!/bin/bash
# This creates one window with 3 panes (one vertical split, one horizontal split),
# and one window with 2 panes (one vertical split).
# -d = detached mode
tmux new-session -d
tmux split-window -h # vertical split
tmux split-window # horizontal split
const JsDom = require("jsdom").JSDOM;
const fs = require("fs");
const elmJs = fs.readFileSync(__dirname + "/elm.js", "utf8");
const html = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
use std::time::{SystemTime, UNIX_EPOCH};
fn get_time() -> FieldResult<i32> {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|t| t.as_secs() as i32)
.map_err(|_| FieldError::new("yeh", graphql_value!({ "internal_error": "oops" })))
}
@ronanyeah
ronanyeah / elm.re
Created June 25, 2019 17:20
Elm + ReasonML + Parcel
// index.html
// <body>
// <div id="app"></div>
// <script src="./main.re"></script>
// </body>
// Open modules sparingly...
open Webapi.Dom;
// Abstract type for our Elm app
pub struct Options {
//var default_normalize_email_options = {
// The following options apply to all email addresses
// Lowercases the local part of the email address.
// Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024).
// The domain is always lowercased, as per RFC 1035
all_lowercase: bool,
// The following conversions are specific to GMail
// Lowercases the local part of the GMail address (known to be case-insensitive)
gmail_lowercase: bool,
module Main exposing (main)
import Browser
import Element exposing (Attribute, centerX, column, el, padding, spacing, text)
import Element.Border as Border
import Element.Input as Input
import Html exposing (Html, button, div)
import Html.Attributes
const { publicKey, privateKey } = await crypto.generateKey(
{
name: "RSA-OAEP",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: "SHA-256"
},
true,
["encrypt", "decrypt"]
);