Skip to content

Instantly share code, notes, and snippets.

@NickAger
NickAger / ExpressionParser.hs
Last active March 23, 2022 11:13
ExpressionParser
-- https://wiki.haskell.org/Parsing_a_simple_imperative_language
-- currently doesn't support floating point or functions.
module Main where
import System.IO
import Control.Monad
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Expr
import Text.ParserCombinators.Parsec.Language
import qualified Text.ParserCombinators.Parsec.Token as Token
use rsc::{tokenize, parse, Interpreter, TokenizeError, ParseError, InterpretError};
// error handling based on:
// * https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/wrap_error.html
#[derive(Debug)]
struct EquationError(pub String);
impl<'input_string> From<TokenizeError<'input_string>> for EquationError {
fn from(err: TokenizeError<'input_string>) -> EquationError {
@NickAger
NickAger / main.rs
Last active February 14, 2022 20:03
Attempt to simplify parsing code shown in https://github.com/fivemoreminix/rsc but didn't work
use std::fmt;
use rsc::{tokenize, parse, Interpreter, TokenizeError, ParseError, InterpretError};
// error handling based on:
// * https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/wrap_error.html
// Unfortunately this didn't work in the context of `fn evaluate` as:
// 1) `cannot return value referencing local variable `tokens``
// 2) `cannot return value referencing local variable `expr``
// `ParseError` contains a reference to a Token rather than copy of it
import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3"
const s3client = new S3Client({logger: console})
@NickAger
NickAger / gist:4029b28bc748b9a5957f5bba9eaff568
Created February 22, 2021 13:36
jq json to csv with transpose
https://jqplay.org
Transpose json into csv columns
see: https://stackoverflow.com/questions/48224065/jq-convert-json-file-with-arrays-to-csv-transposed
[.[]] | transpose[] | @csv
input:
{
# from: https://ericasadun.com/2019/11/19/taking-charge-of-those-xips/
man -t grep | open -f -a /System/Applications/Preview.app
man -t open | open -f -a /System/Applications/Preview.app
# The -t flag tells man to use the Groff typesetter to format the page to postscript. This presents as a PDF in Preview. (Specifically, it uses /usr/bin/groff -Tps -mandoc -c if that kind of detail intrigues you.)
private let dateFormatter:ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone.current
formatter.formatOptions = [.withFullDate, .withFullTime, .withDashSeparatorInDate, .withColonSeparatorInTime, .withSpaceBetweenDateAndTime]
return formatter
}()
let date = dateFormatter.date(from: "2019-08-15 12:57:45 +0000")
@NickAger
NickAger / ServerLocalHost.hs
Created March 8, 2019 14:02
Haskell web server from the a local directory
#!/usr/bin/env stack
-- stack runghc --resolver lts-12.4 --install-ghc --package wai-app-static --package warp
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.String
import Network.Wai.Application.Static (staticApp,defaultFileServerSettings)
import Network.Wai.Handler.Warp (runSettings, setPort, defaultSettings, run)
@NickAger
NickAger / ServeScotty.hs
Created March 8, 2019 14:01
Haskell scotty example
#!/usr/bin/env stack
-- stack runghc --resolver lts-12.4 --install-ghc --package scotty --package wai --package warp --package wai-middleware-static
{-# LANGUAGE OverloadedStrings #-}
module Main where
-- import Web.Scotty
-- import qualified Text.Blaze.Html5 as H
-- import Text.Blaze.Html5 (toHtml, Html)
@NickAger
NickAger / CloudFormationS3Console.yml
Last active March 8, 2019 14:03
Minimum policy requirements to access the S3 console for uploading and downloading files
# Permissions to allow access to S3 console for read and write, see:
# https://stackoverflow.com/questions/6615168/is-there-an-s3-policy-for-limiting-access-to-only-see-access-one-bucket
# https://aws.amazon.com/blogs/security/writing-iam-policies-how-to-grant-access-to-an-amazon-s3-bucket/
DeployUser:
Type: AWS::IAM::User
Properties:
UserName: 'aname@domain.com'
LoginProfile:
Password: apassword
# PasswordResetRequired: true