Skip to content

Instantly share code, notes, and snippets.

View atomkirk's full-sized avatar

Adam Kirk atomkirk

View GitHub Profile
@atomkirk
atomkirk / udot_regions.sql
Created March 8, 2022 19:59
UDOT Regions 1 & 2 GIS
This file has been truncated, but you can view the full file.
INSERT INTO "public"."gis__objects"("id","layer","geometry","properties","inserted_at")
VALUES
(E'udotreg1',E'udot_regions',E'SRID=4326;POLYGON((-113.47488600498771 41.9933094053436,-113.47701796048186 41.993290592340216,-113.47965799142257 41.993267513722095,-113.48183048968212 41.993248275413805,-113.48442960325997 41.9932255219256,-113.48659558154715 41.993206333678295,-113.48914726497632 41.99318405086824,-113.49136078839656 41.99316446201844,-113.492336364185 41.993155700446096,-113.49386453053565 41.99313573035917,-113.49620402201325 41.99310529484248,-113.49858127956367 41.99307443869104,-113.50104721969728 41.99304241079656,-113.50292987922532 41.993017833210615,-113.50597269767145 41.99297851586337,-113.50791966759073 41.99295317178795,-113.51089816756081 41.99291467895187,-113.51203139408835 41.99289968747675,-113.51290988984236 41.99289062542413,-113.51576741908306 41.99286132012711,-113.51790018395923 41.9928393870467,-113.5206364298568 41.99281127081749,-113.52289058677229 41.992788109236464,-113
@atomkirk
atomkirk / factory.ex
Last active March 2, 2022 17:50
Generating Example Data in Elixir
defmodule App.Factory do
alias App.Repo
def create(module, overrides \\ %{})
def create(module, overrides) when is_list(overrides), do: create(module, Map.new(overrides))
def create(module, overrides) do
attributes = module.example() |> Map.merge(overrides)
struct(module)
@atomkirk
atomkirk / endpoint.ex
Created February 23, 2018 16:50
raw body plug parser
plug Plug.Parsers,
parsers: [ZB.Parsers.RAWBODY, :urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Poison
@atomkirk
atomkirk / postgres_enum_add.sql
Created February 9, 2021 14:22
Add postgres enum values in order (for sort)
ALTER TYPE enum_type ADD VALUE 'new_value'; -- appends to list
ALTER TYPE enum_type ADD VALUE 'new_value' BEFORE 'old_value';
ALTER TYPE enum_type ADD VALUE 'new_value' AFTER 'old_value';
@atomkirk
atomkirk / explaination.md
Last active July 1, 2020 13:26
Run Elixir tests on VSCode save

A really great workflow is to write your test first (TDD anyone?), run the test to verify it fails (eliminate false positive) and then write the implementation. I've included a runOnSave setting to run a test file anytime it is saved and, second, to run any failed tests as soon as any other elixir file is saved.

So, you write the test, save, it fails. You write Elixir code, save, it still fails. You keep writing Elixir code and saving until it passes.

This is obviously cool. But one thing that is particularly cool is that while you are writing the implementation, you often want to peek at values and experiment with code. Well, thats easy! Just write the code, IO.inspect it and then save! You'll instantly

@atomkirk
atomkirk / spectre.md
Last active June 3, 2020 23:10
Spectre

Here's my explanation of the Spectre vulnerability

Let's say you create an array numbers in javascript with length 4 and [1, 2, 3, 4] in it.

And lets say it ends up next to a sensative password, in memory belonging to your password manager app.

-----------------------------------------------
1 | 2 | 3 | 4 | p | a | $ | $ | w | o | r | d |
-----------------------------------------------
@atomkirk
atomkirk / elixir-tuple-vs-list.md
Last active April 15, 2020 21:56
elixir tuple constant time

Whats the fastest way to look up an index in Elixir?

Lets create a long list of a million items and look up the 500,000th item

iex(54)> range = 1..1_000_000
1..1000000

iex(55)> index = 500_000
500000
@atomkirk
atomkirk / gist:61b0dfe9866461f6e17f920721b785cc
Created March 7, 2019 13:05
watchOS complication placeholder icon size
182x182
203x203
224x224
300x94
32x32
342x108
36x36
40x40
44x44
50x50
@atomkirk
atomkirk / gcloud-function-printenv.sh
Created April 28, 2018 13:06
printenv of google cloud function
X_GOOGLE_FUNCTION_TIMEOUT_SEC=540
X_GOOGLE_FUNCTION_MEMORY_MB=2048
FUNCTION_TIMEOUT_SEC=540
SHLVL=1
FUNCTION_MEMORY_MB=2048
X_GOOGLE_FUNCTION_TRIGGER_TYPE=CLOUD_STORAGE_TRIGGER
PORT=8080
ENTRY_POINT=**********
OLDPWD=/var/tmp/worker/
HOME=/tmp
@atomkirk
atomkirk / create_sublime_completions.ex
Last active January 17, 2019 16:44
Create Sublime completions file from elixir project
defmodule Mix.Tasks.CreateSublimeCompletions do
use Mix.Task
@moduledoc """
Add this mix file to your project, update `@sublime_dir` and run it periodically to
create a Sublime completions file to get fast code completion in Sublime for your Elixir project.
"""
def run(_args) do
create_completions_file()