Skip to content

Instantly share code, notes, and snippets.

@creationix
creationix / jsonparse.js
Created February 13, 2012 23:20
event-only version of jsonparse
// Named constants with unique integer values
var C = {};
// Tokenizer States
var START = C.START = 0x11;
var TRUE1 = C.TRUE1 = 0x21;
var TRUE2 = C.TRUE2 = 0x22;
var TRUE3 = C.TRUE3 = 0x23;
var FALSE1 = C.FALSE1 = 0x31;
var FALSE2 = C.FALSE2 = 0x32;
var FALSE3 = C.FALSE3 = 0x33;
@domenic
domenic / portable-node.md
Created May 25, 2012 21:03
Tips for Writing Portable Node.js Code

Node.js core does its best to treat every platform equally. Even if most Node developers use OS X day to day, some use Windows, and most everyone deploys to Linux or Solaris. So it's important to keep your code portable between platforms, whether you're writing a library or an application.

Predictably, most cross-platform issues come from Windows. Things just work differently there! But if you're careful, and follow some simple best practices, your code can run just as well on Windows systems.

Paths and URLs

On Windows, paths are constructed with backslashes instead of forward slashes. So if you do your directory manipulation

@sebmarkbage
sebmarkbage / react-terminology.md
Last active January 9, 2023 22:47
React (Virtual) DOM Terminology
@rgaidot
rgaidot / Awesome-Electronic-and-Hardware-platform.md
Last active May 8, 2022 02:52
Awesome Electronic and Hardware platform
@entaq
entaq / Google_oAuth.js
Created November 15, 2012 17:18
Google oAuth 2.0 sample
/**
reference -
https://developers.google.com/accounts/docs/OAuth2WebServer
https://code.google.com/apis/console/
https://developers.google.com/+/api/latest/
**/
////handle all requests here
function doGet(e) {
@jonikarppinen
jonikarppinen / CustomErrorController.java
Last active June 16, 2021 02:19
Example of replacing Spring Boot "whitelabel" error page with custom error responses (with JSON response body)
package com.company.project.controllers;
import com.company.project.model.api.ErrorJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
@dbainbridge
dbainbridge / app.js
Created April 19, 2012 20:48
How to use socket.io with Express 3
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http');
var app = express();
var server = app.listen(3000);
@sebmarkbage
sebmarkbage / ReactCanvasDrawing.js
Created July 25, 2014 19:14
Canvas Drawing Example
/** @jsx React.DOM */
var Graphic = React.createClass({
componentDidMount: function() {
var context = this.getDOMNode().getContext('2d');
this.paint(context);
},
componentDidUpdate: function() {
@ryanmcgrath
ryanmcgrath / twitter_streaming.js
Created February 18, 2011 08:02
Access the Twitter Streaming API with ease (Node.js).
var util = require('util'),
http = require('http'),
events = require('events');
var Twitter = function(opts) {
this.username = opts.username;
this.password = opts.password;
this.track = opts.track;
this.data = '';
};
@SimplGy
SimplGy / promise.js
Last active April 17, 2020 20:55
Sample Promise Implementation. Wrote in https://coderpad.io/626322
// --------------------------------------------- Promise Implementation
Promise = function () {
this._stack = [];
this._isResolved = false;
}
Promise.prototype = {
success: function(callback){
// Is the promise already resolved?
if(this._isResolved) {
callback( this._result );