Skip to content

Instantly share code, notes, and snippets.

loilo /
Last active April 27, 2023 00:21
Make Vue events bubble

Make Vue events bubble

Vue events don't bubble the component tree on their own. However when writing wrapper components this can be the desired behaviour.

This code registers a global bubble directive which allows to re-emit all given events:

Let's say we want to bubble events start, accelerate and brake of our component Car.

Without any help, we'd roughly have to do this:

antishok / NODE_ENV
Last active September 25, 2020 07:09
What does `NODE_ENV=production` do?
dImrich / curved3Plane.js
Created January 6, 2017 18:00
Bend Three JS Plane Geometry With Bezier Curve
//Bend Three JS plane geometry with bezier curve
//Curved plane generation, bezier curve plane,
function bendPlaneGeometry(planeGeometry, centerBendZ)
var curve = new THREE.CubicBezierCurve3(
new THREE.Vector3(planeGeometry.parameters.width/2, 0, centerBendZ ),
new THREE.Vector3(planeGeometry.parameters.width/2, 0, centerBendZ ),
planeGeometry.vertices[(planeGeometry.vertices.length/2) - 1]
theatlasroom / basic-post-receive-hook-with-pm2
Last active August 16, 2022 23:00
Basic post-receive hook - node + pm2
# This is for an expressjs node app, it uses npm + bower packages and pm2 to start the app
# [pm2](
# Assumes you've created a [bare git repo]( with on your server with git init --bare
# Adapted from
mrded / server.js
Created December 4, 2015 16:17
CORS Proxy on node.js + express
var express = require('express'),
request = require('request');
var app = express();
// Forward all requests from /api to
app.use('/api', function(req, res) {
req.pipe(request("" + req.url)).pipe(res);
CMCDragonkai / ternary_comparison.hs
Last active October 31, 2015 00:33
Haskell: Ternary Comparison Operators (inspired by ternary choice operator
The comparison operators are non-associative and not composable.
Thus it is illegal to write: 1 < 2 < 3
The input types of < (Int) does not match the output type (Bool).
1 < 2 < 3 can however be written in math notation, because it denotes:
(1 < 2) && (2 < 3) or (1 < 2) ^ (2 < 3)
It is however possible to create a new ternary operator that supports such a
branneman /
Last active June 29, 2024 16:00
Better local require() paths for Node.js

Better local require() paths for Node.js


When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

var bases = require('bases');
var crypto = require('crypto');
// Returns a base-62 (alphanumeric only) string of the given length:
function randomStr(length) {
// We generate a random number in a space at least as big as 62^length,
// and if it's too big, we just retry. This is still statistically O(1)
// since repeated probabilities less than one converge to zero. Hat-tip to
// a Google interview for teaching me this technique! ;)
ricardobeat / node-0.8.20-hangup.js
Created February 21, 2013 19:27
Silence socket hangup errors.
function hangups (req, res, next){
var reqd = domain.create()
reqd.on('error', function (error) {
if (error.code !== 'ECONNRESET') console.error(error, req.url)
punund /
Created November 11, 2012 19:57
Retrieves first chunk of data of remote image via HTTP GET to find out its size in pixels. PNG, JPEG
getImageSize = (image, cb) ->
fromHex = (hex) -> parseInt "0x#{hex}", 16
req = http.request image, (res) ->
res.setEncoding 'hex'
res.on 'error', (e) -> cb "getImageSize error (#{image}): " + e, null, image
res.on 'data', (chunk) ->
m = switch res.headers['content-type']
when 'image/jpeg'
chunk.match 'ffc0001108(....)(....)'
when 'image/png'