Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt
parsonsmatt / prismatic.hs
Created June 5, 2018 20:49
I figured out a nice way to pluck exceptions out of a constraint!
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@enricofoltran
enricofoltran / main.go
Last active January 22, 2025 07:38
A simple golang web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
@regilero
regilero / nginx.conf
Last active February 26, 2021 12:22 — forked from thoop/nginx.conf
Altered prerender.io nginx.conf for nginx
# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats
# Change example.com (server_name) to your website url
# Change /path/to/your/root to the correct value
# Generate $prerender_ua bool value based on user agent
# indexation bots will get this as 1,
# prerender user agent will always get 0 (avoid loops)
map $http_user_agent $prerender_ua {
default 0;
@mtesseract
mtesseract / haskell-records.md
Last active March 8, 2023 22:25
Working around Haskell's namespace problem for records

The Problem

Defining records in Haskell causes accessor functions for the record's fields to be defined. There is no seperate namespace for these accessor functions.

The Goal

Be able to

  • use records in Haskell, which share field names.
  • use lenses for accessing these fields
@mightybyte
mightybyte / location.hs
Created September 29, 2015 17:40
Reflex Location Management
------------------------------------------------------------------------------
-- | Gets the current path of the DOM Window (i.e., the contents of the
-- address bar after the host, beginning with a "/").
-- https://developer.mozilla.org/en-US/docs/Web/API/Location
getWindowLocationPathname :: DOMWindow -> IO String
#ifdef ghcjs_HOST_OS
getWindowLocationPathname w = do
jw <- toJSRef w
liftM fromJSString $ js_windowLocationPathname jw
@paldepind
paldepind / form.hs
Last active February 5, 2016 01:56
Helper function for creating forms in Reflex. The default of forms is prevented. A submit event and child is returned.
import GHCJS.DOM.EventM (event, preventDefault)
import GHCJS.DOM.Element
form :: MonadWidget t m => m a -> m (Event t (), a)
form child = do
(form, ch) <- el' "form" child
submit <- wrapDomEvent (_el_element form) elementOnsubmit (void $ preventDefault)
performEvent_ (return () <$ submit)
return (submit, ch)
@samselikoff
samselikoff / future-proof.md
Last active August 15, 2024 15:17
Future-proofing your Ember 1.x code

This post is also on my blog, since Gist doesn't support @ notifications.


Components are taking center stage in Ember 2.0. Here are some things you can do today to make the transition as smooth as possible:

  • Use Ember CLI
  • In general, replace views + controllers with components
  • Only use controllers at the top-level for receiving data from the route, and use Ember.Controller instead of Ember.ArrayController or Ember.ObjectController
  • Fetch data in your route, and set it as normal properties on your top-level controller. Export an Ember.Controller, otherwise a proxy will be generated. You can use Ember.RSVP.hash to simulate setting normal props on your controller.
@plentz
plentz / nginx.conf
Last active March 28, 2025 17:48
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@henrik
henrik / base_breadcrumbs.rb
Last active December 17, 2015 16:19
First stab at extracting breadcrumb trail building from the controller. Uses breadcrumbs_on_rails (https://github.com/weppos/breadcrumbs_on_rails) and attr_extras (https://github.com/barsoom/attr_extras).
class BaseBreadcrumbs
private
def c
controller
end
def edit?
%w[edit update].include?(controller.action_name)
end
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article &lt; ActiveRecord::Base