Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
module Poptics where
import Prelude hiding (traverse)
import Control.Category ((>>>))
import Control.Applicative (liftA2, Const (..))
import Control.Arrow ((&&&), (|||), (***))
newtype State s a = State { run :: s -> (a,s)}
@lfborjas
lfborjas / postgres-upsert.sql
Created February 26, 2021 23:47
Upsert that always returns in Postgres
-- :name insert-or-get-image! :<! :1
/* :doc insert an image, or retrieve existing, and return the id, uri, and
public URL as determined by the provided `:bucket` and `:images-host`.
*/
WITH new_img AS (
INSERT INTO image (uri, fmt, size, device_id, os_version_id)
VALUES (:uri, :fmt, :size, :device-id, :os-version-id)
ON CONFLICT (uri) DO NOTHING
RETURNING id, uri,
gcs_uri_to_public_url(uri, COALESCE(:bucket, ''), COALESCE(:images-host, ''))
@lfborjas
lfborjas / Dockerfile
Created December 14, 2020 01:00 — forked from TimWSpence/Dockerfile
Optimized multistage Dockerfile for Haskell Stack builds
# Loosely based on https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker
FROM fpco/stack-build:lts-13.27 as dependencies
RUN mkdir /opt/build
WORKDIR /opt/build
# GHC dynamically links its compilation targets to lib gmp
RUN apt-get update \
&& apt-get download libgmp10
RUN mv libgmp*.deb libgmp.deb
@lfborjas
lfborjas / mens.sql
Last active November 14, 2015 06:49
Flipping: M Nov 2015
CREATE TEMPORARY TABLE boxes_to_restore
(rebillable_id int(10) unsigned,
bh_id int(10) unsigned,
billing_frequency tinyint(3) unsigned,
prev_cycle_status int(10) unsigned,
unique index (rebillable_id),
unique index (bh_id));
INSERT INTO boxes_to_restore (rebillable_id, bh_id, billing_frequency, prev_cycle_status)
SELECT rs.rebillable_id as rebillable_id, bh2.id as bh_id, rs.billing_frequency as billing_frequency, COALESCE(SUM(ctl.result='success')*100 - SUM(ctl.result='failure'),0) as prev_cycle_status
@lfborjas
lfborjas / luis.vim
Created January 26, 2015 16:09
vimrc
syntax on
autocmd Filetype html setlocal ts=2 sw=2 expandtab
autocmd Filetype ruby setlocal ts=2 sw=2 expandtab
autocmd Filetype javascript setlocal ts=2 sw=2 expandtab
autocmd Filetype cucumber setlocal ts=2 sw=2 expandtab
set noswapfile
au BufRead,BufNewFile *.md set filetype=markdown
au BufRead,BufNewFile *.md.html set filetype=markdown
function activarFormulario(){
var form = document.querySelector("form");
form.addEventListener("submit", function(event) {
event.preventDefault();
var r = document.getElementById("result");
var n = document.getElementById("GET-nombre");
r.textContent = n.value;
});
}
class Dog < Animal
def pet
dog_petter.pet
end
private
def dog_petter
DogPetter.new
end
end
@lfborjas
lfborjas / application.rb
Created July 31, 2013 12:25
inspect the rack env before it hits the rails app
#config/application.rb
config.middleware.use "Peekaboo"
@lfborjas
lfborjas / Gemfile
Last active December 15, 2015 03:59
prueba de concepto de app
gem 'sinatra'
gem 'rest-client'
gem 'json' #probablemente innecesaria
@lfborjas
lfborjas / fake_endpoints.rb
Created March 18, 2013 13:46
Serves a rack app based on paths/responses defined in a cucumber feature
require 'gherkin/parser/parser'
require 'gherkin/formatter/json_formatter'
#This is intended to be mounted on top of a rails app with
#mount FakeEndpoints => "/fake_api"
#this allows clients to play around with an intended implementation of the API without it being actually coded at all
#the features look like
# Given I GET /an/endpoint; Then the JSON response is:
class FakeEndpoints
def initialize
@routes = gather_routes