Skip to content

Instantly share code, notes, and snippets.

View atomkirk's full-sized avatar

Adam Kirk atomkirk

View GitHub Profile
@atomkirk
atomkirk / ios-camera.html
Created March 13, 2020 04:49
iOS Safari Camera API
<video id="player" autoplay muted playsinline> </video>
<button id="capture">Capture</button>
<canvas id="canvas" width=320 height=240></canvas>
<script>
const player = document.getElementById('player');
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const captureButton = document.getElementById('capture');
const constraints = {
@atomkirk
atomkirk / hungarian.ex
Last active January 8, 2023 20:25
Hungarian/Munkres algorithm in Elixir
defmodule Hungarian do
@moduledoc """
Written by Adam Kirk – Jan 18, 2020
Most helpful resources used:
https://www.youtube.com/watch?v=dQDZNHwuuOY
https://www.youtube.com/watch?v=cQ5MsiGaDY8
https://www.geeksforgeeks.org/hungarian-algorithm-assignment-problem-set-1-introduction/
@atomkirk
atomkirk / cloud-files.md
Last active April 8, 2025 12:15
Storing files on S3 with Elixir

I have this abstraction in my application code called a "CloudFile". This is where I store in the database information about files on S3 and it gives me a resource for other resources to own. For example, a user would have an avatar_cloud_file_id. On the front-end, I would load this relationship and display the avatar with user.avatar_cloud_file.download_url

defmodule RL.CloudFile do
  use Ecto.Schema
  import Ecto.Changeset

  @timestamps_opts type: :utc_datetime_usec
@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 / custom_segue.swift
Last active February 26, 2023 15:50
Custom Fade In/Out Segue
import UIKit
// All you do is assign this class to a segue in your storyboard and you're done
class BottomCardSegue: UIStoryboardSegue {
private var selfRetainer: BottomCardSegue? = nil
override func perform() {
destination.transitioningDelegate = self
@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()
@atomkirk
atomkirk / example.sh
Created November 8, 2018 03:01
compose airmail command line args
osascript sendEmail.applescript 'hello there you' [email protected] [email protected] [email protected]
@atomkirk
atomkirk / difference_between_strings.ex
Created September 21, 2018 02:03
Elixir format difference in strings
@doc """
Truncates the middle of a string
iex> Utils.String.truncate_middle("some really long string that needs truncating", 10)
"some..ting"
iex> Utils.String.truncate_middle("some really long string that needs truncating", 100)
"some really long string that needs truncating"
"""
def truncate_middle(str, count) when is_binary(str) and is_integer(count) do
@atomkirk
atomkirk / parsce-csv-test.js
Last active February 13, 2023 09:19
parse csv with javascript
import parseCsv from 'zipbooks/utils/parse-csv'
import { module, test } from 'qunit'
module('Unit | Utility | parse-csv', function(_hooks) {
test('parses csv successfully', function(assert) {
let result = parseCsv('name,age\nadam,31\ntim,32\n"St, clair",26')
assert.equal(JSON.stringify(result), '[["name","age"],["adam","31"],["tim","32"],["St, clair","26"]]')
})
@atomkirk
atomkirk / format-cc.js
Created July 5, 2018 15:04
credit card formatter
const blocks = {
uatp: [4, 5, 6],
amex: [4, 6, 5],
diners: [4, 6, 4],
discover: [4, 4, 4, 4],
mastercard: [4, 4, 4, 4],
dankort: [4, 4, 4, 4],
instapayment: [4, 4, 4, 4],
jcb15: [4, 6, 5],
jcb: [4, 4, 4, 4],