Skip to content

Instantly share code, notes, and snippets.

@forficate
forficate / randpass
Created January 7, 2017 12:56
Random password generator shellscript
#/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: pass [size]"
exit 1
fi
PASS=$(openssl rand -base64 256 | tr -cd '[:alnum:]' | head -c${1:-$1})
echo $PASS | pbcopy
echo $PASS
@forficate
forficate / RequestId.hs
Last active September 28, 2016 11:25
WAI middleware to generate a unique id for a request. This can be used in logging for tracing log lines by request id and debugging errors by taking the response X-REQUEST-ID header and searching in logs for it.
{-# LANGUAGE OverloadedStrings #-}
module MyApp.Wai.Middleware.RequestId (injectRequestId, hRequestId) where
import Data.ByteString (ByteString)
import Data.UUID (toASCIIBytes)
import Data.UUID.V4 (nextRandom)
import Network.HTTP.Types.Header
import Network.Wai
@forficate
forficate / Task.elm
Created October 11, 2015 07:05
elm-lang Task snippers
-- Allow both the left / right values of a task to be promted in to a successful Task of c
fold : (a -> c) -> (b -> c) -> Task a b -> Task y c
fold f1 f2 t =
Task.map f2 t `Task.onError` (\x -> Task.succeed(f1 x))
@forficate
forficate / using_mailboxes_in_elm.md
Created October 7, 2015 13:48 — forked from mgold/using_mailboxes_in_elm.md
Using Mailboxes in Elm: a tutorial blog post

Using Mailboxes in Elm

Max Goldstein | July 30, 2015 | Elm 0.15.1

In Elm, signals always have a data source associated with them. Window.dimensions is exactly what you think it is, and you can't send your own events on it. You can derive your own signals from these primitives using map, filter, and merge, but the timing of events is beyond your control.

This becomes a problem when you try to add UI elements. We want to be able to add checkboxes and dropdown menus, and to receive the current state of these elements as a signal. So how do we do that?

The Bad Old Days

@forficate
forficate / Main.elm
Created October 1, 2015 15:02 — forked from dpwiz/Main.elm
Render, minify and compress Elm project.
module Main where
import Html (..)
import Html.Attributes (..)
import Html.Events (..)
import List
import LocalChannel as LC
import Signal
-- Model
# Get a refresh token for a client.
We use offline so we can access the account without the user needing to reauthenticate https://developers.google.com/identity/protocols/OAuth2WebServer
Also see the Web server applications sequence diagram at Web server applications
```
client_id=""
scopes="email profile"
csrf="some csrf token to validate"
@forficate
forficate / main.rb
Last active August 29, 2015 14:10 — forked from anonymous/main.rb
Search my bitbucket repos from alfred
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
require_relative "bundle/bundler/setup"
require "alfred"
require 'json'
basic_user = ENV['BB_USER_NAME']
basic_password = ENV['BB_PASSWORD']
@forficate
forficate / delayedItervalArrayIterator.js
Created July 7, 2014 23:14
Javascript Array delayed interval iterator
//Iterates over each item in an array at a delayed interval (1500ms)
Array.prototype.iterate = function (callback, onFinished) {
var self = this;
(function get(index){
setTimeout(function(){
if(index < self.length) {
callback(self[index], index);
get(index + 1);
} else {
sub vcl_recv {
#FASTLY recv
if (req.request != "HEAD" && req.request != "GET" && req.request != "PURGE") {
return(pass);
}
#Dissable access to these at varnish
if (req.url ~ "install\.php|update\.php|cron\.php|apc.php|user/register") {
error 404 "Page not found.";