Skip to content

Instantly share code, notes, and snippets.

Dean Radcliffe deanius

View GitHub Profile
View async_ruby.rb
# some of the syntax requires Ruby 2.5+
module Async
refine BasicObject do
def async(&block)
Async::Context.new(&block).run!
end
def enqueue(&block)
::Fiber.yield [:append, block]
end
@JoshCheek
JoshCheek / observer_async_options.js
Last active Mar 6, 2019
Three variations on async
View observer_async_options.js
// based on https://github.com/deanius/async-gen-vs-events/blob/3ad02c4af7ab7c56178e4614bb1585220ccec8db/walk_dir_tree_with_events.js
// three different algorithms on async, with a fake file system that's easy to modify
const { agent } = require("rx-helper");
// Timer (useful for understanding how output gets processed)
const start = new Date()
const log = (whatevz) => console.log(new Date() - start, whatevz)
// Fake slow file system:
@gaearon
gaearon / connect.js
Last active Apr 25, 2019
connect.js explained
View connect.js
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@deanius
deanius / _README.md
Last active Aug 29, 2015
Meteor package.json for fun and profit
View _README.md

Why use pacakge.json with Meteor ?

  • Keep the preferred port with the project
  • Each project need not run on port 3000 (Keep your favicon.ico from getting confused!)
  • Start up with settings.json in a conventional way
  • Install utils with your project, like spacejam, ESLint, etc..
  • Have a uniform interface between package projects and meteor apps

How to use it ?

@nolanlawson
nolanlawson / protips.js
Last active Apr 16, 2019
Promise protips - stuff I wish I had known when I started with Promises
View protips.js
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
View extract_meteor_deps.js
// p = require('./extract_meteor_deps');
// Package = p.Package;
// getPackageDeps = p.getPackageDeps; depsByPackage = p.depsByPackage;
//
// > getPackageDeps('spacebars')
// ['htmljs', 'blaze', 'observe-sequence', 'templating']
// > depsByPackage
// {"spacebars": ['htmljs', 'blaze', 'observe-sequence', 'templating']}
var Package, api, depsByPackage, getPackageDeps, mockApiUse, _;
@deanius
deanius / load-it.js
Last active Aug 29, 2015
Load core Meteor Libraries for a Meteor-style REPL in the browser
View load-it.js
var loadScript = function(url){
var d=document;
var s=d.createElement('script');
s.src=url;
(d.head || d.documentElement).appendChild(s)
};
/*needed for reactive-coffee, and meteor*/
loadScript('http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js');
/*Tracker.autorun (as Meteor.run), ReactiveDict (as ReactiveMap), ReactiveVar, and ReactiveObject */
loadScript('https://s3.amazonaws.com/www.chicagogrooves.com/js/mini-meteor.js');
@fraserxu
fraserxu / auth.js
Last active Feb 6, 2018
Handling CORS in Meteor app
View auth.js
/*
* packages/reststop2/auth.js
* Add a method to handle OPTIONS request
*/
// return nothing
RESTstop.add('login', {'method': 'OPTIONS'}, function() {})
View 1-meteor-internationalization.bash
# This little gist shows how to easily internationalize your application using the meteor-just-i18n package.
# Package repository: https://github.com/subhog/meteor-just-i18n/
# 1. Adding the package.
$ meteor add anti:i18n
@CrabDude
CrabDude / callback_contract.md
Created Apr 16, 2014
Node.js Callback Contract
View callback_contract.md

#callback/errback contract

  1. Function that takes 2 arguments
    • first argument is an error
    • second argument is the result
    • Never pass both
    • error should be instanceof Error
  2. Must never excecute on the same tick of the event loop
  3. Must be passed as last argument to function
  4. Return value is ignored
  5. Must not throw / must pass resulting errors
You can’t perform that action at this time.