Skip to content

Instantly share code, notes, and snippets.

View cgarvis's full-sized avatar
👋

Chris Garvis cgarvis

👋
View GitHub Profile
@cgarvis
cgarvis / website.ex
Created May 20, 2021 13:02
Download zip, extract, and parse csv in Elixir
defmodule Website do
alias NimbleCSV.RFC4180, as: CSV
def fetch_data(url) do
with {:ok, resp} <- HTTPoison.get(report.url, [timeout: 50_000]),
{:ok, files} <- :zip.extract(resp.body),
{_name, content} <- hd(files),
rows <- CSV.parse_string(content)
do
{:ok, rows}
@cgarvis
cgarvis / Makefile
Last active September 22, 2020 18:21
Makefile for AWS SAM Golang project
SAM_PACKAGE_TEMPLATE = ./aws-sam/build/template.yaml
SAM_TEMPLATE = ./template.yaml
SAM_INFRA_DEPENDENCIES := $(shell find infra -type f)
.PHONY: $(SAM_INFRA_DEPENDENCIES)
$(SAM_INFRA_DEPENDENCIES):
cfn-lint $@
.PHONY:lint
lint: ## Lint cloudformation template
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import "AppDelegate.h"
@cgarvis
cgarvis / behaviors.js
Created December 16, 2014 17:57
React Behaviors
var React = require('react');
var List = require('./list.js');
function registerBehavior(reactClass, selector) {
var mountingNodes = document.querySelectorAll(selector);
for(var i = 0; i< mountingNodes.length; i++) {
React.render(React.createElement(reactClass), mountingNodes[i]);
}
}
@cgarvis
cgarvis / image_proxy_controller.rb
Last active February 2, 2022 13:24
Image Proxy in Rails
require 'base64'
require 'net/http'
class ImageProxyController < ActionController::Base
def get
url = URI.parse(Base64.decode64(params[:url]))
image = Net::HTTP.get_response(url)
send_data image.body, type: image.content_type, disposition: 'inline'
end
end
package main
import(
"net/http"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
type ResponseTester struct {
response *http.Response
@cgarvis
cgarvis / onEnter.coffee
Created April 4, 2013 13:34
angular.js onEnter Directive
'use strict'
angular.module('app')
.directive 'onEnter', () ->
(scope, element, attrs) ->
element.bind "keydown keypress", (event) ->
if event.which is 13
scope.$apply () ->
scope.$eval(attrs.onEnter)
event.preventDefault()
@cgarvis
cgarvis / create_customer.rb
Created March 12, 2013 17:35
Possible approach to a hexagonal gem with rspec test
module HexagonalGem
class CreateCustomer
attr_reader :listener, :validator
def self.create customer, listener = {}
c = CreateCustomer.new(listener)
c.create(customer)
end
def initialize(listener)
@cgarvis
cgarvis / moveline.zsh-theme
Created January 22, 2013 18:08
ZSH Theme for Moveline
# ------------------------------------------------------------------------
# Christopher Garvis
# oh-my-zsh theme
# Totally ripped-off Tyler Cipriani
# ------------------------------------------------------------------------
# Grab the current date (%W) and time (%t):
#bold MOVELINE_TIME_="%{$fg_bold[red]%}#%{$fg_bold[white]%}( %{$fg_bold[yellow]%}%W%{$reset_color%}@%{$fg_bold[white]%}%t )( %{$reset_color%}"
MOVELINE_TIME_="%{$fg[red]%}#%{$fg_bold[white]%}( %{$fg[yellow]%}%W%{$reset_color%}@%{$fg_bold[white]%}%t )( %{$reset_color%}"