Skip to content

Instantly share code, notes, and snippets.

@craigp
craigp / history_stuff.sql
Created September 25, 2023 02:49 — forked from slotrans/history_stuff.sql
Building blocks for generic history-keeping in Postgres.
/*
Replace "your_schema" with whatever schema is appropriate in your environment.
It is possible to use "public"... but you shouldn't!
*/
/*
Function to stamp a "modified" timestamp. Adjust the name to suit your environment,
but that name is hard-coded so it is assumed that you only use _one_ such name.
@craigp
craigp / Convert .mov or .MP4 to .gif.md
Created October 10, 2022 00:28 — forked from SheldonWangRJT/Convert .mov or .MP4 to .gif.md
Convert Movie(.mov) file to Gif(.gif) file in one command line in Mac Terminal

This notes is written by Sheldon. You can find me with #iOSBySheldon in Github, Youtube, Facebook, etc.

Need

Convert .mov/.MP4 to .gif

Reason

As a developer, I feel better to upload a short video when I create the pull request to show other viewers what I did in this PR. I tried .mov format directly got after finishing recording screen using Quicktime, however, gif offers preview in most web pages, and has smaller file size.

This is not limited to developer, anyone has this need can use this method to convert the files.

@craigp
craigp / wtf-sns-apns.js
Created May 29, 2019 05:03 — forked from brianleroux/wtf-sns-apns.js
Send a silent push notification to APNS with AWS SNS.
sns.publish({
TargetArn: device.arn,
MessageStructure: 'json',
Message: JSON.stringify({
default: 'you will never see this muah!',
APNS_SANDBOX: JSON.stringify({
aps: {
'alert': '',
'content-available': 1
},
@craigp
craigp / pre_push
Created July 30, 2018 10:02 — forked from sascha-wolf/pre_push
Elixir pre-push hook for git - ensures files are formatted correctly and credo is satisfied
#!/bin/bash
ask() {
# https://djm.me/ask
local prompt default reply
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
@craigp
craigp / transcode
Created May 26, 2018 18:07 — forked from datashaman/transcode
Convert audio to 320kbps CBR .mp3, convert video to x264 .mp4
#!/usr/bin/env bash
#
# Usage:
# transcode filename [filename...]
#
# File type is determined using:
#
# file --mime-type filename
#
# Audio files:
@craigp
craigp / .iex.exs
Created August 4, 2017 13:34 — forked from fertapric/.iex.exs
Prompt Mix env on IEX (with colors)
env = case System.get_env("MIX_ENV") || "dev" do
"prod" -> IO.ANSI.red() <> "prod" <> IO.ANSI.reset()
"dev" -> IO.ANSI.green() <> "dev" <> IO.ANSI.reset()
"test" -> IO.ANSI.green() <> "test" <> IO.ANSI.reset()
mix_env -> IO.ANSI.yellow() <> mix_env <> IO.ANSI.reset()
end
IEx.configure(
default_prompt: "%prefix(#{env},%counter)>",
alive_prompt: "%prefix(#{env},%node,%counter)>"
@craigp
craigp / migrate.sh
Created June 16, 2017 06:34 — forked from gaynetdinov/migrate.sh
How to run Ecto migrations from an exrm release
$./bin/my_app rpc Elixir.Application app_dir "[my_app, <<\"/priv/repo/migrations\">>]."
<<"/home/dashboard/uss/lib/my_app-0.0.1/priv/repo/migrations">>
./bin/my_app rpc Elixir.Ecto.Migrator run "['Elixir.MyApp.Repo', <<\"/home/dashboard/uss/lib/my_app-0.0.1/priv/repo/migrations\">>, up, [{all, true}]]."
# => []
@craigp
craigp / twitter_stream.ex
Created June 15, 2017 18:22 — forked from mgwidmann/twitter_stream.ex
Infinite Streams with Elixir
# Elixir has lazily evaluated enumerable objects that allow you
# to work with enumerable objects like lists either only as needed
# or infinitely.
# Start up iex to play around
$ iex
# Typical enumeration is done eagerly where the result is computed ASAP
iex> Enum.map(1..10, fn i -> i * 2 end)
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
@craigp
craigp / deprecation.md
Created May 23, 2017 14:38 — forked from KronicDeth/deprecation.md
HowTo make deprecation warnings in Elixir

TIL how to make deprecation warnings:

Compiling 2 files (.ex)
warning: `Retort.Resources.timeout/2` is deprecated; call `Retort.Resources.Timeout.get_or_default/2` instead.
  lib/retort/resources.ex:197: Retort.Resources.timeout/2

Replace function

defmodule Quicksort do
def sort([]), do: []
def sort([head|tail]) do
{low, high} = Enum.partition(tail, &(&1 < head))
sort(low) ++ [head] ++ sort(high)
end
end