Skip to content

Instantly share code, notes, and snippets.

Avatar

David King oodavid

View GitHub Profile
@oodavid
oodavid / main.dart
Created Jan 22, 2020
Dart > Sort List<Map> by multiple keys
View main.dart
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;
}
}
View From StreamBuilder to MultiProvider.dart
/// 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()
View .editorconfig
# 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 Jun 22, 2017
Create a new repo from a directory within an existing repo
View clone.md

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 Sep 19, 2016
Scraper Example
View package.json
{
"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 Aug 11, 2018
Automatically renew letsencrypt SSL certificates via cron.
View ssl-letsencrypt-auto-renew.sh
#!/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 Nov 29, 2015
Execute this file from a local git repo to create repos on your webserver to act as a remote AND working master branch
View server.gitready.sh
#!/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 Aug 29, 2015
GC > New Groups Paradigm Bug
View Application.js
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 Aug 29, 2015
devkit v3 upgrade - android build issues - IRC fix
View gist:65d0f5ca76b8cd8bd9e1
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 Dec 16, 2014
GameClosure > Particles
View Particles.js
/** 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 +
*/
You can’t perform that action at this time.