Skip to content

Instantly share code, notes, and snippets.

@bfcoder
bfcoder / gist:6638fbe2a67b449426de830e951acb59
Created March 3, 2023 18:13
Docker build imagemagick in alpine linux with heic support
FROM alpine
ARG IMAGICK_VERSION="7.1.0-62"
# Add build tooling and dependencies
RUN apk add --no-cache --virtual .build-deps \
build-base \
libde265-dev \
libheif-dev
@bfcoder
bfcoder / gist:3fbd5c38e296d1ce259a86770a04f973
Created March 3, 2023 18:12
Docker build imagemagick in ubuntu 22.04 with heic support
FROM public.ecr.aws/docker/library/ubuntu:22.04
RUN sed -i "s|^# deb-src http:\/\/archive.ubuntu.com\/ubuntu\/ jammy universe|deb-src http://archive.ubuntu.com/ubuntu\/ jammy universe|g" /etc/apt/sources.list
RUN sed -i "s|# deb-src http:\/\/archive.ubuntu.com\/ubuntu\/ jammy-updates universe|deb-src http://archive.ubuntu.com/ubuntu\/ jammy-updates universe|g" /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y \
build-essential \
wget \
git \

Run Length Encoding

Implement run-length encoding and decoding.

Run-length encoding (RLE) is a simple form of data compression, where runs (consecutive data elements) are replaced by just one data value and count.

For example we can represent the original 53 characters with only 13.

@bfcoder
bfcoder / array_prototypes.js
Created December 14, 2015 19:13
Compare two arrays
// http://stackoverflow.com/a/17980268/1477165
// var arr1 = [1, 2, 3, 4];
// var arr2 = [2, 1, 4, 3]; // Loosely equal to 1
// var arr3 = [2, 2, 3, 4]; // Not equal to 1
// var arr4 = [1, 2, 3, 4]; // Strictly equal to 1
// arr1.equals(arr2); // false
// arr1.equals(arr2, false); // true
// arr1.equals(arr3); // false
@bfcoder
bfcoder / empty-json-case.sql
Created September 29, 2015 20:09
PostgreSQL (9.2+) : How to return an empty json array from an empty resultset.
/* will return null::json on empty resultset */
SELECT array_to_json(array_agg(row_to_json(t))) FROM t;
/*
will return '[]' on empty resultset,
null::json seems to be managed the same way than sql NULL by COALESCE()
*/
SELECT COALESCE(array_to_json(array_agg(row_to_json(t))), '[]') FROM t;
@bfcoder
bfcoder / prepend-use-strict.js
Last active August 29, 2015 14:25 — forked from blaise-io/prepend-use-strict.js
Prepend all JavaScript files with "use strict"; that don't have it yet
// To run:
// npm install globby
// node prepend-use-strict.js
var globby = require('globby');
var fs = require('fs');
globby('**/*.js', function(err, files) {
for (var i = 0, m = files.length; i < m; i++) {
var fileContent = fs.readFileSync(files[i]).toString();
@bfcoder
bfcoder / Launch Canvas Starter Script
Created June 10, 2015 18:07
Apple Script Project Launcher
(choose from list {"Large", "Laptop"} with prompt "Which Screen Size?")
set screen_size to result as text
set window_group to "Common"
if (screen_size = "Large") then
set window_group to "Freightlink_large"
end if
if (screen_size = "Laptop") then
@bfcoder
bfcoder / current_user.js
Created May 22, 2015 15:52
Ember 1.12 current_user initializer
Ember.Application.initializer({
name: 'currentUser',
initialize: function(registry, application) {
// Register the `user:current` namespace
application.register("user:current", App.CurrentUserController, { singleton: true });
// Inject the namespace into controllers and routes
application.inject('route', 'currentUser', "user:current");
application.inject('controller', 'currentUser', "user:current");
Steps to install and run PostgreSQL 9.2 using Homebrew (Mac OS X)
(if you aren't using version 9.1.5, change line 6 with the correct version)
1. launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
2. mv /usr/local/var/postgres /usr/local/var/postgres91
3. brew update
4. brew upgrade postgresql
5. initdb /usr/local/var/postgres -E utf8
6. pg_upgrade -b /usr/local/Cellar/postgresql/9.1.5/bin -B /usr/local/Cellar/postgresql/9.2.0/bin -d /usr/local/var/postgres91 -D /usr/local/var/postgres
7. cp /usr/local/Cellar/postgresql/9.2.0/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/