Skip to content

Instantly share code, notes, and snippets.

@sirmews
sirmews / ec2-userdata.sh
Created April 23, 2023 05:05
ubuntu docker ec2 user data
#!/bin/bash
apt-get update -y
apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update -y
apt-get install -y docker-ce docker-ce-cli containerd.io
usermod -aG docker ubuntu
@sirmews
sirmews / grab_vimeo_thumbnail.php
Created March 4, 2021 06:12 — forked from bacoords/grab_vimeo_thumbnail.php
Grab a thumbnail of a private (but embeddable) Vimeo video
<?php
/**
* Grab the url of a publicly embeddable video hosted on vimeo
* @param str $video_url The "embed" url of a video
* @return str The url of the thumbnail, or false if there's an error
*/
function grab_vimeo_thumbnail($vimeo_url){
if( !$vimeo_url ) return false;
$data = json_decode( file_get_contents( 'http://vimeo.com/api/oembed.json?url=' . $vimeo_url ) );
@sirmews
sirmews / lambda.js
Created November 19, 2020 04:31 — forked from streamich/lambda.js
using node-postgres (`pg`) in AWS Lambda
import λ from "apex.js";
import { Pool } from "pg";
// connection details inherited from environment
const pool = new Pool({
max: 1,
min: 0,
idleTimeoutMillis: 120000,
connectionTimeoutMillis: 10000
});
const doNecessaryKeysExist = (obj) => {
const neededKeys = ['GID', 'day_part', 'day']
let expectedTrueValues = neededKeys.length
let trueValues = neededKeys.reduce((a, prop) => {
return a + (prop in obj && obj[prop] !== null)
}, 0);
return expectedTrueValues === trueValues
}
@sirmews
sirmews / README.md
Created July 20, 2019 00:44 — forked from notheotherben/README.md
Fix Postgres 9.x Sequences

PostgreSQL 9.x Sequence Fixing Script

This script is intended to automatically fix the sequence numbers for all tables in the current database.

This is accomplished through the use of the setval() command, which we provide with the next ID value we wish to make use of. We use the setval(sequence, number, is_called) overload and set is_called = false in conjunction with COALESCE(MAX + 1, 1) to ensure that, with an empty table, the next sequence value is 1 as expected.

@sirmews
sirmews / groupBy.ts
Created May 22, 2019 03:55 — forked from guillaumegarcia13/groupBy.ts
groupBy in Typescript (for use in Angular)
declare global {
interface Array<T> {
groupBy(prop: T): Array<T>;
}
}
if (!Array.prototype.groupBy) {
Array.prototype.groupBy = (prop: string) => {
return this.reduce(function(groups, item) {
const val = item[prop];
@sirmews
sirmews / groupBy.js
Created May 22, 2019 02:10 — forked from ramsunvtech/groupBy.js
Group By - ES6
function groupBy(list, props) {
return list.reduce((a, b) => {
(a[b[props]] = a[b[props]] || []).push(b);
return a;
}, {});
}
// Usage.
groupBy([{
id: 1,
@sirmews
sirmews / install-ngrok-macos.md
Last active April 29, 2019 02:53
Installing ngrok on Mac OS

Manual

Download from ngrok.com

mv ~/Whatever/ngrok /Applications/

via symlink

ln -s /Applications/ngrok /usr/local/bin

@sirmews
sirmews / gist:2d20dc08bb28be6bcff8d1dd11c3cd48
Created February 20, 2018 04:24
download zip master from github with curl
curl -LJO https://file/master
@sirmews
sirmews / ffmpeg_convert_all_to_mp3.sh
Created January 2, 2018 05:55
ffmpeg_convert_all_to_mp3
#!/bin/bash
for i in *.m4a; do
ffmpeg -i "$i" -codec:a libmp3lame -qscale:a 2 `basename "$i" .m4a`.mp3
done