Skip to content

Instantly share code, notes, and snippets.

View mg's full-sized avatar

Magnús Örn Gylfason mg

View GitHub Profile
@mg
mg / bgglog.dart
Last active February 28, 2024 10:00
Log gameplay to BGG example
import 'dart:convert';
import 'package:http/http.dart' as http;
const BGGLOGIN_URL = 'https://boardgamegeek.com/login/api/v1';
const BGGUPLOAD_URL = 'https://boardgamegeek.com/geekplay.php';
enum UploadResult {
Success,
UsernamePassword,
NetworkError,
class MyListNotifier extends ValueNotifier<MyList> {
MyListNotifier(MyList myList) : super(myList) {
value.setNotifyListeners(notifyListeners);
}
}
class MyList<E> extends List<E> {
VoidCallback _notifyListeners;
void setNotifyListeners(VoidCallback notifyListeners) {
this.notifyListeners = notifyListeners;
class MyWidget extends StatefulWidget {
final GlobalKey myKey = GlobalKey();
MyWidget();
@override
State<StatefulWidget> createState() => MyWidgetState();
}
class MyWidgetState extends State<MyWidget> {
@override
@mg
mg / copy.js
Created July 25, 2016 11:20
Copy Amazon Kindle Highlights in Chrome
var items= document.getElementsByClassName("highlight")
var lines= []
for(var i= 0; i < items.length; i++) lines.push(items[i].innerText)
copy(lines.join("\n\n"))
@mg
mg / HOC-for-context-and-props.jsx
Created November 22, 2015 18:37
Describing a pattern I use to leverage the benefits context in React.js but still keeping my components simple
/*
This pattern is useful when using context in React to pass values down
the component tree. The example I use here is localization but I use it every
time I use contexts in React
*/
/*
Locale is a Higher Order Component that creates the "locale" context. Components
that are locale sensitive can use this context value to both get the active
locale and to be notified when the locale changes. It also puts the function
let promises= [...]
function wrap(inner) {
let outer= new Promise()
inner.then(result => {
outer.resolve(result)
}).catch(error) {
outer.resolve(error)
}
return outer
@mg
mg / rxsnippets.js
Last active August 29, 2015 14:15
Rx.js snippets
/*
Drag & Drop
*/
var parent= document.getElementById('parent');
var widget= document.getElementById('widget');
var mouseDowns= Observable.fromEvent(widget, 'mousedown');
var parentMouseMoves= Observable.fromEvent(parent, 'mousemove');
var parentMouseUp= Observable.fromEvent(parent, 'mosueup');
@mg
mg / unixcommands
Created January 25, 2015 21:25
Unix commands
# go sloc
find . -name "*.go" | grep -v test.go | xargs wc -l | sort -n
@mg
mg / obj.js
Created December 22, 2014 10:45
function prop(obj, name, get, set) {
var base= name.substr(0,1).toUpperCase() + name.substr(1);
if(!get) {
get= function() {
return this['_' + name];
};
}
if(!set) {
set= function(v) {
@mg
mg / gist:d77de48cbca4b43e16e9
Created September 2, 2014 13:09
AngularJS/ToddMotto
// http://toddmotto.com/opinionated-angular-js-styleguide-for-teams/
(function() {
/**
* Describe controller
*
* @param $scope
* @param p1
* @constructor
*/