Skip to content

Instantly share code, notes, and snippets.

Mark Penner mnpenner

Block or report user

Report or block mnpenner

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ags131
ags131 / apitoken.js
Created Oct 27, 2016
apitoken mod for screeps server
View apitoken.js
// Add a new function to player sandbox space
// Some Super Secret Secret (32 character hex string)
const secret = Buffer.from('DEADBEEF000000000000000000000000', 'hex')
const jwt = require('./lib/jwt')
module.exports = function (config) {
if (config.engine) {
config.engine.onPlayerSandbox = function (sandbox) {
sandbox.getAPIToken = function () {
let key = generateToken(sandbox.module.user)
@moodysalem
moodysalem / promise-cancellable.js
Last active Apr 11, 2019
ES6 Cancellable Promise Wrapper
View promise-cancellable.js
/**
* Returns a promise that has a cancelled method that will cause the callbacks not to fire when it resolves or rejects
* @param promise to wrap
* @returns new promise that will only resolve or reject if cancel is not called
*/
export default function cancellable(promise) {
var cancelled = false;
const toReturn = new Promise((resolve, reject) => {
promise.then(() => {
@Nilpo
Nilpo / password_api_test.php
Created Jan 8, 2016
A simple PHP script for testing what cost you should use with your server for password_hash() in PHP 5.5.0+
View password_api_test.php
<?php
/**
* This code will benchmark your server to determine how high of a cost you can
* afford. You want to set the highest cost that you can without slowing down
* you server too much. 8-10 is a good baseline, and more is good if your servers
* are fast enough. The code below aims for ≤ 50 milliseconds stretching time,
* which is a good baseline for systems handling interactive logins.
*/
function_exists('password_hash') or die("Please use PHP 5.5.0 or higher.");
@OlegIlyenko
OlegIlyenko / Event-stream based GraphQL subscriptions.md
Last active Aug 21, 2019
Event-stream based GraphQL subscriptions for real-time updates
View Event-stream based GraphQL subscriptions.md

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.

@smarr
smarr / truffle-material.md
Last active Aug 12, 2019
Truffle: Languages and Material
View truffle-material.md
@dzhu
dzhu / screeps.py
Last active Aug 31, 2018
description of the HTTP endpoints available from Screeps, and a Python wrapper to access them (requires requests library)
View screeps.py
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
@jwcarroll
jwcarroll / screeps.d.ts
Created Aug 17, 2015
TypeScript Definition Files for The Game Screeps
View screeps.d.ts
declare var Game: screeps.IGame;
declare module screeps {
export interface IGame {
cpuLimit: number;
creeps: { [screepName: string]: ICreep };
flags: { [flagName: string]: IFlag };
map: IMap;
rooms: { [roomName: string]: IRoom };
@mnylen
mnylen / _.md
Last active May 28, 2019
Debounced fetching to reduce number of requests when doing API proxying through GraphQL
View _.md

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 https://github.com/graphql/graphql-js/issues/19#issuecomment-119370037

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

{
  latestPrograms(first: 10) {
    name,
    playcount
View react-clearfix.js
'use strict';
import React from 'react';
export default class Clearfix extends React.Component {
render() {
const beforeStyle = {
display: 'table'
};
@fxg42
fxg42 / index.js
Last active Feb 26, 2016
Using Bluebird Promises, MongoDB and Babel's async/await with Bluebird's coroutines
View index.js
import Promise from 'bluebird'
import MongoDB from 'mongodb'
Promise.promisifyAll(MongoDB)
async function findEveryone(db) {
const people = db.collection('people')
const everyone = await people.find().toArrayAsync()
return everyone.map( x => x.name )
}
You can’t perform that action at this time.