Skip to content

Instantly share code, notes, and snippets.

View plamb's full-sized avatar

Paul Lamb plamb

  • Oklahoma City, OK
View GitHub Profile
src_pdf (original, current pdf)
append_pdf (has new pages)
dest_pdf (becomes new)
if start_page > 0
copy src_pdf to archive
if start_page = 0 or start_page = 1
copy append_pdf to src_pdf filename
else

Input file has records and subrecords

^RECORD(1,2,3,"key-1",1)
abc
^(2)
cde
^(3)
fgh
^(4)
ijk
@plamb
plamb / Dockerfile
Created April 8, 2016 13:27
docker exrm (many months old, might be way outdated)
# This image is designed as a base image to use in creating exrm releases. It
# includes quite a few things that you would not need for just a pure runtime
# but is also suitable to use as a base for a phoenix app (you may need to add
# npm for handling the static assets)
FROM debian:jessie
MAINTAINER Someone <someone@somewhere.com>
ENV DEBIAN_FRONTEND noninteractive
@plamb
plamb / gist:c7c011bf487b1125d4e8
Created January 7, 2016 03:00
IO.inspect from LiveReloader.call
[info] Running PathTest.Endpoint with Cowboy using http on port 4000
06 Jan 20:57:26 - info: compiled 5 files into 2 files, copied 3 in 934ms
%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{},
before_send: [], body_params: %Plug.Conn.Unfetched{aspect: :body_params},
cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false,
host: "localhost", method: "GET", owner: #PID<0.443.0>,
params: %Plug.Conn.Unfetched{aspect: :params}, path_info: ["phoenix"],
peer: {{127, 0, 0, 1}, 56094}, port: 4000,
private: %{phoenix_endpoint: PathTest.Endpoint},
query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: "",
@plamb
plamb / gce_auth.ex
Last active December 9, 2020 14:31
Authenticate with Google Cloud using service account json key and Elixir
# https://developers.google.com/identity/protocols/OAuth2ServiceAccount
key_json = File.read!("some-service-account-key-file.json")
key_map = JOSE.decode(key_json)
jwk = JOSE.JWK.from_pem(key_map["private_key"])
jws = %{"alg" => "RS256"}
header = %{
@plamb
plamb / okc_elixir.md
Created October 19, 2015 18:25
OKC Elixir Group

OKC Elixir Study Group -- DRAFT

###Disclaimer I have no freaking idea what I'm doing or if this will even work out but that's never really stopped me from trying. So let's see where it goes. Committing to a group that meets physically together was going to be tough, so I wondered how well a virtual group would work, no travel time, can do it after the kids go to bed, etc. I'm also going to put a time limit on this, both in how long the group meets and how long we do this.

##Concept Over the next 6 months, work through some of the problems in Brian Hogan's Exercises for Programmers using Elixir. Then once or twice a month, we will hold a 45-60 minute skype conference call to discuss problems we had and how we solved them.

###Format

Time Agenda

Just a few thoughts and links that didn't get into the already massively overtime talk.

#Phoenix Showdown Benchmark

https://github.com/mroth/phoenix-showdown

The google-cloud based tests did not acheive the same numbers that were published with the Rackspace setup (I followed their methodology and used the same wrk test loads). You'd need quite a few more client connections than they used to get there. Neither Phoenix nor Rails used more than 50% of the cpu available.

@plamb
plamb / streaming_pg_elixir.md
Last active October 1, 2021 05:36
Streaming json from Postgresql through Phoenix

Streaming json from Postgresql through Phoenix

I wanted to explore the fastest way to have json generated in postgresql delivered through phoenix to the browser. With this, I wanted to completely avoid any decoding/encoding happening in ecto/phoenix since I already had perfectly valid json coming out of pg.

It took some trial and error, and some source code reading, and some help from the list but I've got it working with materialized views and returning them in less than 1ms on my laptop.

Here's the short how-to. I'm using pg 9.4 and this should work with both json and jsonb results. I've also used the generic app/App nomenclature, you'll need to change that to your app's name.

Let's take a really, really simple query that returns some json:

Found this file from my first attempts with Play about a year ago. Hadn't done any more Play until just before Christmas and got a wild thought that I should breath some life into a 15 year old java servlet app that hadn't had anything besides some a couple of css changes since 2001. Thought it would take a week, 90 days later it's about to go live for clients, with some long overdue feature additions (and is now about 80% Scala code, albeit very basic Scala code). I will blog about that soon.

Thoughts on Play Framework from a Rails dev. Part I

Why?

  • Pretty much a pattern of every 4-5 years I decided to try something new that will stretch my thinking and skills
  • Learning a dynamic language completely changed my thinking and processes, functional is something I know very little about
  • Ruby/Rails is cool, there are tons of amazing people, ecosystem is fantastic and don't really want to leave that comfort zone.
  • I have code in java and systems that can't be accessed from ruby but can be from java (or .n
@plamb
plamb / gist:6902733
Last active December 25, 2015 02:29
Multiple join conditions

Here's the simplest way I can think of to describe the problem.

Using the classic posts, authors and comments I need to query for an authors posts and any comments (there may be zero to many comments) for a specific author. Database is postgressql 9.2 and Rails 4.0.

The query should come out something like (this isn't valid sql, need to show that author_id needs to be dynamic):

SELECT * 
FROM POSTS
JOIN AUTHORS ON posts.author_id = authors.id