Skip to content

Instantly share code, notes, and snippets.

@oodavid
oodavid / main.dart
Created January 22, 2020 17:17
Dart > Sort List<Map> by multiple keys
extension SortBy on List {
sortBy(List<String> keys) {
this.sort((a, b) {
for(int k=0; k<keys.length; k++) {
String key = keys[k];
int comparison = Comparable.compare((a[key]??""), (b[key]??""));
if(comparison != 0){
return comparison;
}
}
/// 0 - Example `Streams`
Stream<MyUserModel> userStream => FirebaseAuth
.instance
.onAuthStateChanged
.map((user) => MyUserModel.fromFirebase(user));
String documentPath = 'my/document';
Stream<MyDocumentModel> documentStream = Firestore.instance
.document(documentPath)
.snapshots()
# http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
@oodavid
oodavid / clone.md
Created June 22, 2017 12:09
Create a new repo from a directory within an existing repo

Make sure you have this git alias

git config --global alias.clone-branches '! git branch -a | sed -n "/\/HEAD /d; /\/master$/d; /remotes/p;" | xargs -L1 git checkout -t'

Clone the remote, pull all branches, change the remote, filter your directory, push

git clone git@github.com:user/existing-repo.git new-repo
cd new-repo
git clone-branches

git remote rm origin

@oodavid
oodavid / package.json
Last active September 19, 2016 11:22
Scraper Example
{
"name": "scraper",
"version": "1.0.0",
"description": "Scraper",
"main": "scraper.js",
"dependencies": {
"node-horseman": "^3.1.1",
"random-useragent": "^0.3.0"
}
}
@oodavid
oodavid / ssl-letsencrypt-auto-renew.sh
Last active January 11, 2023 22:17
Automatically renew letsencrypt SSL certificates via cron.
#!/bin/bash
# Source
# https://gist.github.com/oodavid/54cadfb92ff49618797d
# Adapted from
# https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04
# Make sure this is added to the crontab, ie:
# sudo crontab -e
# 30 2 * * 1 /home/ubuntu/khan-draw/ssl-letsencrypt-auto-renew.sh >> /var/log/ssl-letsencrypt-auto-renew.log
# Config
@oodavid
oodavid / server.gitready.sh
Last active August 6, 2022 10:37
Execute this file from a local git repo to create repos on your webserver to act as a remote AND working master branch
#!/bin/bash
# This script is no good for servers with multiple-users, I simply
# designed it to quickly push my git tinkerings to my EC2 test server.
#
# Use at your own risk!
#
# cd to a local directory under git control and execute this script, it will:
# create repos on your server
# modify your local remotes to push to the server
@oodavid
oodavid / Application.js
Last active August 29, 2015 14:25
GC > New Groups Paradigm Bug
import ui.TextView as TextView;
import ui.View as View;
import device;
import animate;
var gx = Math.ceil(device.width/20);
exports = Class(GC.Application, function () {
this.initUI = function () {
// A note
new TextView({
superview: this.view,
@oodavid
oodavid / gist:65d0f5ca76b8cd8bd9e1
Last active August 29, 2015 14:24
devkit v3 upgrade - android build issues - IRC fix
oodavid morning jdwilm
oodavid jdwilm: do you have a moment to look at issues building for android?
jdwilm oodavid: can you check that you have the core folder in native-android?
jdwilm seems like there might be a missing sym link or submodule
oodavid shall do :)
jdwilm I think there is a missing symlink in native-android/TeaLeaf/jni named 'core' which should point to native-android/native-core submodule
jdwilm Incidentally, we could probably just move the submodule and obviate the need for such a link
oodavid jdwilm: yeah, that looks like the case
oodavid just trying to figure out where npm has installed native-android/native-core
jdwilm It should be on $GAME/modules/devkit-core/modules/native-android
@oodavid
oodavid / Particles.js
Created December 16, 2014 08:59
GameClosure > Particles
/** MOLECULE MATCH - Particles
*
* Utility View for GameClosure DevKit to add an
* explosion of Particles anywhere on the screen.
*
* Modified for github
*
* @author David "oodavid" King
* @copyright Copyright (c) 2014 +
*/