Skip to content

Instantly share code, notes, and snippets.

View homerquan's full-sized avatar

Homer Quan homerquan

View GitHub Profile
"scripts": {
"preinstall": "node tools/nodeVersionCheck.js",
"setup": "node tools/setup/setupMessage.js && npm install && node tools/setup/setup.js",
"remove-demo": "babel-node tools/removeDemo.js",
"start-message": "babel-node tools/startMessage.js",
"prestart": "npm run start-message",
"start": "concurrently -k -r -s first \"npm run test:watch\" \"npm run open:src\" \"npm run lint:watch\"",
"open:src": "babel-node tools/srcServer.js",
"open:dist": "babel-node tools/distServer.js",
"lint": "esw webpack.config.* src tools --color",
@homerquan
homerquan / gist:4237d861c80d1c8afd7147bdfa87ef0d
Created March 27, 2019 00:46
apollo client with graphql-subscription 1.x to 2.x
const uri = 'https://api.graph.cool/simple/v1/cj7yuh1df1tnt0147ihz25bgi'
const wsClient = {
uri: 'wss://subscriptions.graph.cool/v1/cj7yuh1df1tnt0147ihz25bgi',
options: {
reconnect: true,
connectionParams: {
authToken: localStorage.getItem(GC_AUTH_TOKEN),
}
}
}
<i class="fa fa-wordpress" aria-hidden="true"></i>
<i class="fa fa-medium" aria-hidden="true"></i>
<i class="fa fa-drupal" aria-hidden="true"></i>
<i class="fa fa-grav" aria-hidden="true"></i>
@homerquan
homerquan / PrivateMethodCaller.scala
Created January 4, 2018 18:33 — forked from jorgeortiz85/PrivateMethodCaller.scala
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))
@homerquan
homerquan / cors.inc
Created December 30, 2017 04:46 — forked from antonbabenko/cors.inc
(nginx AND varnish) + CORS (working example)
more_set_headers "Access-Control-Allow-Origin: $http_origin";
more_set_headers "Access-Control-Allow-Credentials: true";
# OPTIONS indicates a CORS pre-flight request
if ($request_method = 'OPTIONS') {
more_set_headers "Access-Control-Max-Age: 1728000";
more_set_headers "Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS";
more_set_headers "Access-Control-Allow-Headers: Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since";
more_set_headers "Content-Length: 0";
import { withFilter } from 'graphql-subscriptions';
...
Subscription: {
watchDevice: {
resolve: (payload) => payload,
subscribe: withFilter(
() => pubsub.asyncIterator(deviceConstants.UPDATE_DEVICE),
(payload, args) => payload._id.toString() === args.id,
import { withFilter } from 'graphql-subscriptions';
...
Subscription: {
watchDevice: {
resolve: (payload) => payload,
subscribe: withFilter(
() => pubsub.asyncIterator(deviceConstants.UPDATE_DEVICE),
(payload, args) => payload._id.toString() === args.id,
const withDataAndSubscription = graphql(GETIMS_QUERY, {
options({toID}) {
console.log(GETIMS_QUERY);
const fromID = Meteor.userId();
return {
fetchPolicy: 'cache-and-network',
variables: {fromID: `${fromID}`, toID: `${toID}`}
};
}
,
# Stop an actor
## PoisonPill Messages
A PoisonPill message has special handling for all actors, including for routers. When any actor receives a PoisonPill message, that actor will be stopped. See the PoisonPill documentation for details.
```scala
import akka.actor.PoisonPill
router ! PoisonPill
```
import akka.actor._
case class Book(title: String, authors: List[String])
class BookPublisher extends Actor {
def receive = {
case book: Book => {
println(s"Yeah! Publishing a new book: $book")
context.system.eventStream.publish(book)