Skip to content

Instantly share code, notes, and snippets.

@samueleaton
samueleaton / handlers.fs
Last active November 29, 2020 22:44
simple hello world server in F#
namespace MyApp
open Sol.Context
module Middlewares =
let authenticateAdmin next ctx =
let isAdmin = hasQueryParam "is_admin" ctx
@samueleaton
samueleaton / reset.styl
Last active November 24, 2020 13:04
CSS Reset for Stylus
// CSS RESET
html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video
margin 0
padding 0
border 0
outline 0
font-size 100%
vertical-align baseline
background transparent
@samueleaton
samueleaton / poorMansLodash.js
Last active February 13, 2020 23:14
Some basic functionality you would find with lodash
/* eslint-disable id-blacklist */
/* eslint-disable id-length */
/* eslint-disable no-param-reassign */
/* eslint-disable no-implicit-coercion */
/* eslint-disable no-undefined */
/* eslint-disable no-empty-function */
/* eslint-disable semi */
/* eslint-disable quotes */
/* eslint-disable no-eq-nullg */
@samueleaton
samueleaton / remote_address.cr
Created March 15, 2019 00:20
Adds remote_address to server context
require "http/server"
# from https://github.com/crystal-lang/crystal/pull/7302
class HTTP::Request
@io : IO?
def initialize(@method : String, @resource : String, headers : Headers? = nil, body : String | Bytes | IO | Nil = nil, @version = "HTTP/1.1", @io : IO? = nil)
@headers = headers.try(&.dup) || Headers.new
self.body = body
@samueleaton
samueleaton / rand_str.cr
Created December 14, 2018 17:27
Because sometime your need a big alphanumeric string in Crystal
def rand_str(length = 16, supplemental_chars = "")
res = [] of Char
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + supplemental_chars
length.times do { |i| res << chars[rand(chars.size)] }
res.join()
end
rand_str 32
#=> xkURIpYnqbRVj893pr23LhhxeukFTu5f
# Follow guide here:
# https://www.netguru.co/codestories/nginx-tutorial-performance
location /api {
# proxy here
#
# Make all proxy request start with a certain path (ie. /api) so they are quicker and
# we don't have to see if it matches a static asset.
#
# so instead of "http://example.com/users/sam" and NGINX checking if there
@samueleaton
samueleaton / Flatgrammer.sublime-theme
Last active November 16, 2017 16:02
Monokai Phoenix Flat (Sublime Theme)
[
//
// TABS (REGULAR)
//
// Tab set
{
"class": "tabset_control",
"layer0.texture": "",
"layer0.tint": [34,34,34],
"layer0.inner_margin": 2, // Overlay light puck (for dark content)
@samueleaton
samueleaton / dev.dockerfile
Last active September 23, 2017 18:43
Crystal Docker for development
FROM crystallang/crystal:0.22.0
MAINTAINER sam@eaton.party
WORKDIR /app
# copy all your app files/directories to image
COPY static ./static
COPY dev ./dev
COPY spec ./spec
COPY src ./src
COPY shard.yml ./shard.yml
@samueleaton
samueleaton / key-bindings.json
Last active April 1, 2017 22:03
Adds extra space between brackets when using space key in sublime text
[
{ "keys": [" "], "command": "insert_snippet", "args": {"contents": " $0 "}, "context": [
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(\\(|\\[|{) ?$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(\\)|\\]|})", "match_all": true }
]},
{ "keys": [" "], "command": "insert_snippet", "args": {"contents": "$0 "}, "context": [
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(\\(|\\[|{) $", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(\\)|\\]|})", "match_all": true }
]}
]
!function(t){function n(e){if(r[e])return r[e].exports;var i=r[e]={exports:{},id:e,loaded:!1};return t[e].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var r={};return n.m=t,n.c=r,n.p="",n(0)}([function(t,exports,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}n(1);var e=n(286),i=r(e),o=n(287),u=r(o),a=n(290),c=r(a),f=n(291),s=r(f),l=n(292),p=r(l),h=n(293),v=r(h),g=n(294),d=r(g),y=n(295),_=(r(y),n(296)),m=r(_),b=n(297),w=r(b),x=n(298),S=r(x),j=n(299),O=r(j),E=n(300),A=r(E),k=n(301),F=r(k);(function(){function t(){var t=n();c["default"].each(t,r)}function n(){var t=c["default"].toArray(document.getElementsByClassName("embeddable-q-form"));return c["default"].filter(t,function(t){return!t.dataset.built})}function r(t){function n(){console.log("formContainer: ",t),console.log("formContainer.id: ",t.id),q(t.id,t),setTimeout(function(){r()},400)}function r(){t.classList.remove("hide")}if(!t.dataset.built){t.id=(0,O["default"])("embedable-q-form-"),t.dataset.built=!0,t.classList.add("hide