Skip to content

Instantly share code, notes, and snippets.

View mrsinguyen's full-sized avatar
🎯
Focusing

Si Nguyen mrsinguyen

🎯
Focusing
View GitHub Profile
@mrsinguyen
mrsinguyen / 0.md
Created April 18, 2016 09:33 — forked from max-mapper/0.md
JS hoisting by example

JavaScript function hoisting by example

Below are many examples of function hoisting behavior in JavaScript. Ones marked as works successfuly print 'hi!' without errors.

To play around with these examples (recommended) clone them with git and execute them with e.g. node a.js

Notes on hoisting

(I may be using incorrect terms below, please forgive me)

@mrsinguyen
mrsinguyen / GraphQL-Relay-Redux.md
Created March 14, 2016 12:21 — forked from idibidiart/GraphQL-Architecture.md
GraphQL/Relay as Change-Enabling Architecture

GraphQL allows us to define a UI-agnostic data model on the server using a graph schema that encodes the natural relationships within the data. To wire our model to data, we define resolvers in the schema that leverage our db's own query language (SQL, NoSQL, or Graph query language, etc) or in-memory objects to resolve client-defined, graph-oriented "queries" (or, more precisely, graph-oriented RPC) against our UI-agnostic data model.

With each components in the UI component tree declaring its own data dependencies, GraphQL/Relay creates a projection of the graph data model that maps to the UI component tree, thus allowing us to have a UI-agnostic data model on the server, while at once giving us and UI-specific projection of the data. The queries from GraphQL server to the database are composed in an efficient manner based on the aggregate data dependencies that are declared by each component in the UI component tree, thus eliminating redundant queries to the database.

<?php
/**
* @file
* Contains \Drupal\mymodule\Plugin\QueueWorker\MyModuleTaskWorkerEntityUpdate.
*/
namespace Drupal\mymodule\Plugin\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
@mrsinguyen
mrsinguyen / comments.jsx
Created October 16, 2015 06:00 — forked from juampynr/comments.jsx
Render Disqus comments in React
/**
* Comments component.
*
* Displays comments from Disqus for the current URL.
*/
'use strict';
var React = require('react');
var Settings = require('somepath/settings');
var Comments = React.createClass({
@mrsinguyen
mrsinguyen / example_wordpress_migrate.drush.inc
Created September 30, 2015 03:50 — forked from adamzimmermann/example_wordpress_migrate.drush.inc
Programatically Creating and Storing WordPress Migrate Migrations in Drupal
/**
* Define the WordPress blogs to be imported.
*/
function example_wordpress_migrate_wordpress_blogs() {
// Any key not set here will default to the values set in the
// $blog_default_settings variable in the drush command.
$blogs = array(
array(
'domain' => 'www.example.com/site-one/',
),
@mrsinguyen
mrsinguyen / tinytest.api.js
Last active September 14, 2015 06:46 — forked from fgm/tinytest.api.js
Meteor tinytest api
// From 1.1.03 packages/tinytest/tinytest.js
test._stringEqual(actual, expected, message) // Source comment: EXPERIMENTAL nicer (multiline) string display in runner
test.equal(actual, expected, message, not) // Source comment: "XXX eliminate 'message' and 'not' arguments"
/* Call this to fail the test with an exception. Use this to record exceptions
* that occur inside asynchronous callbacks in tests. It should only be used
* with asynchronous tests, and if you call this function, you should make
* sure that
* (1) the test doesn't call its callback (onComplete function);
* (2) the test function doesn't directly raise an exception.
*/
@mrsinguyen
mrsinguyen / singleton.go
Last active September 6, 2015 08:02 — forked from vaskoz/singleton.go
Singleton pattern in Golang
package main
import (
"fmt"
"time"
)
var instance TheOnlyOne = &onlyOne{time.Now()}
type TheOnlyOne interface {

Option 1: Command-line download extension as zip and extract

extension_id=jifpbeccnghkjeaalbbjmodiffmgedin   # change this ID
curl -L -o "$extension_id.zip" "https://clients2.google.com/service/update2/crx?response=redirect&os=mac&arch=x86-64&nacl_arch=x86-64&prod=chromecrx&prodchannel=unknown&prodversion=44.0.2403.130&x=id%3D$extension_id%26uc" 
unzip -d "$extension_id-source" "$extension_id.zip"

Thx to crxviewer for the magic download URL.

@mrsinguyen
mrsinguyen / form.js
Last active August 29, 2015 14:25 — forked from dhcole/form.js
$(function(){
var formUrl = '/* ex: https://docs.google.com/a/developmentseed.org/spreadsheet/formResponse?formkey=... */';
// Set up map
var m = mapbox.map('map').addLayer(mapbox.layer().id(' /* mapbox-account.id */ '));
// Set up map ui features with point selector
var ui = mapbox.ui().map(m).auto().pointselector(function(d) {
// Remove all points except the most recent
@mrsinguyen
mrsinguyen / domains.js
Last active August 29, 2015 14:25 — forked from dhcole/domains.js
var _ = require('underscore');
var async = require('async');
var request = require('request');
var domains = [
// Federal non-.gov domains
{
url: 'http://govt-urls.usa.gov/tematres/vocab/services.php?output=json&task=fetchDown&arg=17',
json: true,
},