Skip to content

Instantly share code, notes, and snippets.

View avdgaag's full-sized avatar

Arjan van der Gaag avdgaag

View GitHub Profile
@avdgaag
avdgaag / stream_csv.ex
Created July 13, 2017 09:28
Streaming CSV straight out of the database to the client using Elixir, Phoenix, Ecto and PostgreSQL.
def index(conn, _params) do
conn = conn
|> put_resp_content_type("text/csv")
|> put_resp_header("content-disposition", "attachment; filename=export.csv")
|> send_cunked(200)
Repo.transaction fn ->
Ecto.Adapters.SQL.stream(Repo, "COPY expensive_report TO STDOUT CSV HEADER")
|> Stream.map(&(chunk(conn, &1.rows)))
|> Stream.run
import Html.App as App
import Html exposing (..)
import Html.Attributes exposing (..)
import Http
import Task
import Json.Decode as Json exposing ((:=))
-- MODEL
type alias Model =

Keybase proof

I hereby claim:

  • I am avdgaag on github.
  • I am avdgaag (https://keybase.io/avdgaag) on keybase.
  • I have a public key whose fingerprint is 4F42 6A06 0AD7 FB17 65C7 F164 7109 F6F2 67B5 C31C

To claim this, I am signing this object:

@avdgaag
avdgaag / gist:c66ad5868d8e699dd639
Last active September 22, 2015 11:56
Example setup API for ROM::Lotus
# Lotus has different applications in a single project, optionally with different configurations and/or mappings.
# ROM::Lotus should/could conigure a different setup per application, rather than a single global setup.
# Relations could be global (defined in ./lib) while mappings might live in both (./apps/web/ and ./lib).
# This would resemble how Lotus::Model is organised.
#
# The only problem here is that Lotus has no hooks for loading framework (it's all hard-coded)s, and
# therefore we can't easily extend the application load process with our custom setup code without
# resorting to monkeypatching.
# apps/web/application.rb
@avdgaag
avdgaag / literate.rb
Created March 4, 2015 20:00
AsciiDoc filter for literate programming-style code blocks.
#!/usr/bin/env ruby
require 'open3'
require 'tmpdir'
module Literate
class Line
INDENT = ''.freeze
def self.indent(str)
@avdgaag
avdgaag / gist:6dc26d8fbba2cd4ce458
Last active August 29, 2015 14:09
Page objects in Ruby for use with Capybara
class ProductForm
attr_reader :page, :form
def initialize(page)
@page = page
@form = page.find('form.new_product')
end
def title=(new_title)
form.fill_in 'product_title', with: new_title
@avdgaag
avdgaag / issue-completion.vim
Created July 28, 2014 18:26
Autocomplete Github issue numbers from Vim using a custom completion function, Ruby and the Github API.
function! MyOmniFunc(findstart, base)
if a:findstart
let existing = matchstr(getline('.')[0:col('.')-1],'#\d*$')
return col('.')-1-strlen(existing)
endif
ruby << EOF
require 'open-uri'
require 'json'
def issues(repo, token)
@avdgaag
avdgaag / things.sh
Last active January 20, 2023 17:50
Command-line read-only interface to your local Things database of to do items.
#!/bin/bash
#
# DESCRIPTION
#
# Simple read-only comand-line interface to your Things 2 database. Since
# Things uses a SQLite database (which should come pre-installed on your Mac)
# we can simply query it straight from the command line.
#
# We only do read operations since we don't want to mess up your data.
#
@avdgaag
avdgaag / gist:7427844
Created November 12, 2013 09:10
Git pre-commit hook to reject commits that contain Git conflict markers.
#!/bin/sh
# Add this to .git/hooks/pre-commit to reject any commits
# that contain Git conflict markers.
if git diff --cached --name-only --diff-filter=ACM | xargs grep -H -n -E '^(<|>|=|\|){7}' > /dev/null; then
echo "\033[31mWarning:\033[0m You have left some Git conflict markers in."
echo 'Your commit is bad and you should feel bad.'
echo
git diff --cached --name-only --diff-filter=ACM | xargs grep -H -n -E '^(<|>|=|\|){7}'
exit 1
@avdgaag
avdgaag / gist:6865420
Last active December 24, 2015 21:29
Run Rubocop using the project settings on modified files in your Git repository. Store this in `.git/hooks/pre-commit` to reject commits with style offsenses.
#!/bin/bash
git diff --cached --name-status --diff-filter=ACM | awk '/\.rb$/ { print $2 }' | xargs rubocop -f s
exit_code=$?
if [[ $exit_code != 0 ]] ; then
echo 'Your commit was rejected because Rubocop found style guide violations.'
echo 'Run `rake rubocop` to test your code and inspect the offenses Rubocop'
echo 'has found.'
echo
echo 'If you really, REALLY want to commit this code, skip your pre-commit'
echo 'hooks with `git commit --no-verify`.'