Skip to content

Instantly share code, notes, and snippets.

View mnpenner's full-sized avatar
:octocat:

Mark Penner mnpenner

:octocat:
View GitHub Profile
@dzhu
dzhu / screeps.py
Last active November 14, 2020 10:18
description of the HTTP endpoints available from Screeps, and a Python wrapper to access them (requires requests library)
import json
from base64 import b64decode
from collections import OrderedDict
from cStringIO import StringIO
from gzip import GzipFile
import requests
## Python before 2.7.10 or so has somewhat broken SSL support that throws a warning; suppress it
@mnylen
mnylen / _.md
Last active April 23, 2021 21:17
Debounced fetching to reduce number of requests when doing API proxying through GraphQL

Simple implementation of debounced fetching in GraphQL to allow merging of multiple rest / database requests into one. Although this example uses GraphQL, the debouncedFetch / fetchProgramPlaycount implementations could probably be used in any context to achieve the same result.

This approach was first described by @leebyron at graphql/graphql-js#19 (comment)

For example this allows turning ten requests for playcounts from this GraphQL query into just one:

{
  latestPrograms(first: 10) {
    name,

playcount

@eirikbacker
eirikbacker / addEventListener-polyfill.js
Created June 3, 2012 19:30
addEventListener polyfill for IE6+
//addEventListener polyfill 1.0 / Eirik Backer / MIT Licence
(function(win, doc){
if(win.addEventListener)return; //No need to polyfill
function docHijack(p){var old = doc[p];doc[p] = function(v){return addListen(old(v))}}
function addEvent(on, fn, self){
return (self = this).attachEvent('on' + on, function(e){
var e = e || win.event;
e.preventDefault = e.preventDefault || function(){e.returnValue = false}
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true}
@jerone
jerone / WE-Markdown.css
Last active January 12, 2022 01:19
Github Flavored Markdown Stylesheet for Web Essentials
html {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
font-family: sans-serif;
}
body {
margin: 0;
padding: 30px;
min-width: 1020px;
@aknosis
aknosis / calendar.twig
Created October 22, 2012 15:52
Table based calendar only using Twig
{#
time can be any string acceptable by http://www.php.net/strtotime, the
template will output that time's month.
If you don't want to pass in a date you can set time like this:
{% set time = "now"|date("U") %}
{% set time = "December 2012"|date("U") %}
How ever you want to output items onto the calendar is a different issue,
but I'd assume pushing everything into an array numerically indexed by that day:
@aaronpowell
aaronpowell / selectMany.js
Created November 19, 2012 03:22
LINQ SelectMany in JavaScript
Array.prototype.selectMany = function (fn) {
return this.map(fn).reduce(function (x, y) { return x.concat(y); }, []);
};
// usage
console.log([[1,2,3], [4,5,6]].selectMany(function (x) { return x; })); //[1,2,3,4,5,6]
console.log([{ a: [1,2,3] }, { a: [4,5,6] }].selectMany(function (x) { return x.a; }));
@smarr
smarr / truffle-material.md
Last active March 16, 2023 14:06
Truffle: Languages and Material

Moved to repo: /quenhus/uBlock-Origin-dev-filter

In order to keep filters up to date, please use this repo.

@sebmarkbage
sebmarkbage / WhyReact.md
Created September 4, 2019 20:33
Why is React doing this?

I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.

I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.

"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr

@OlegIlyenko
OlegIlyenko / Event-stream based GraphQL subscriptions.md
Last active February 24, 2024 04:41
Event-stream based GraphQL subscriptions for real-time updates

In this gist I would like to describe an idea for GraphQL subscriptions. It was inspired by conversations about subscriptions in the GraphQL slack channel and different GH issues, like #89 and #411.

Conceptual Model

At the moment GraphQL allows 2 types of queries:

  • query
  • mutation

Reference implementation also adds the third type: subscription. It does not have any semantics yet, so here I would like to propose one possible semantics interpretation and the reasoning behind it.