Skip to content

Instantly share code, notes, and snippets.

@rcy
rcy / model.js
Created July 2, 2014 17:10
simple model wrapper for Meteor collections
Model = {
create: function (collection, methods) {
var model = function (doc) {
_.extend(this, doc);
};
_.extend(model.prototype, methods);
collection._transform = function (doc) {
return new model(doc);
};
@rcy
rcy / bootstrap-3
Created August 26, 2014 23:37
bootstrap 3 meteor 0.9.0
rcy@laird:~/tmp$ meteor --version
Meteor 0.9.0
rcy@laird:~/tmp$ meteor create myapp
myapp: created.
To run your new app:
cd myapp
meteor
rcy@laird:~/tmp$ cd myapp
@rcy
rcy / insertonlyonce.js
Last active August 29, 2015 14:05
a user can insert a document one time into a collection, after that, the insert is denied
// some random collection
Things = new Meteor.Collection('things');
// collection used to track users who are blocked from inserting
Blocked = new Meteor.Collection('blocked');
if (Meteor.isServer) {
Meteor.startup(function () {
// remove all documents on startup for testing purposes
Blocked.remove({});
@rcy
rcy / apolloclient.js
Created May 18, 2017 23:51
apollo client setup for meteor
import { createMeteorNetworkInterface, meteorClientConfig } from 'meteor/apollo';
import { ApolloClient } from 'react-apollo';
import { SubscriptionClient, addGraphQLSubscriptions } from 'subscriptions-transport-ws';
const wsClient = new SubscriptionClient('ws://localhost:5000/', {
reconnect: true,
});
// Create a normal network interface:
@rcy
rcy / graphcool.subtest.js
Last active July 20, 2017 17:19
component to test mutation updates and subscriptions on graphql/graphcool
import React, { Component } from 'react';
import { gql, graphql, withApollo, compose } from 'react-apollo';
class Box extends Component {
state = {
mutateCount: 0, // the number of times we have called mutate()
subCount: 0, // the number of times we have received subscription event
};
componentWillMount() {
(progn
(condition-case nil
(scroll-down 1)
(error nil))
(message "got here"))
;; simpler version of above
(progn
(ignore-errors (scroll-down 1))
(message "got here"))
(defun rcirc-reposition-to-bottom (orig-fun &rest args)
"Reposition the window to put point at bottom line."
(when (and (eq major-mode 'rcirc-mode)
(eq (point) (point-max))
(recenter -1))))
(advice-add 'text-scale-adjust :after #'rcirc-reposition-to-bottom)
@rcy
rcy / rehash.sh
Created August 29, 2020 18:02
Recompute hashes for graphile-migrate migration files
#!/bin/bash
#
# usage: rehash.sh committed/*.sql
#
# This will update each file's Previous and Hash values
#
function sum {
sha1sum | cut -d' ' -f1
}
@rcy
rcy / machine.js
Last active March 30, 2021 23:29
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@rcy
rcy / machine.js
Created May 10, 2021 19:03
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions