Skip to content

Instantly share code, notes, and snippets.

View rafayepes's full-sized avatar

Rafa Yepes rafayepes

View GitHub Profile
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>crypto</title>
</head>
<body>
<script src="./node_modules/vault-cipher/lib/crypto-js/aes.js"></script>
<script src="./node_modules/vault-cipher/lib/crypto-js/pbkdf2.js"></script>
@branneman
branneman / better-nodejs-require-paths.md
Last active June 24, 2025 22:40
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

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

@rauschma
rauschma / umd.js
Last active April 8, 2018 02:26
My version of the UMD pattern. https://github.com/umdjs/umd
if (typeof define !== 'function') {
// Not AMD
if (typeof require === 'function') {
// Node.js
var define = function (body) {
module.exports = body(require);
};
} else {
// Vanilla browser
var define = function (body) {
@aearly
aearly / Gruntfile.js
Last active June 24, 2016 06:43
Annotated Browserify Gruntfile
/**
* Annotated Gruntfile.
* This builds a Backbone/Marionette application using Dust.js (Linkedin fork) as a
* templating system, as well as some helpers from Foundation, with Browserify.
* It also configures a watcher and static server with live reload.
*/
module.exports = function (grunt) {
// This automatically loads grunt tasks from node_modules
require("load-grunt-tasks")(grunt);
@staltz
staltz / introrx.md
Last active July 19, 2025 08:08
The introduction to Reactive Programming you've been missing
@esnunes
esnunes / sample.js
Last active August 29, 2015 14:05
react flux dispatcher promises with circular dependency detection
var Promise = require('es6-promise').Promise;
var handlerA = function () {
return waitFor([handlerB])
.then(function () {
console.log('handlerA');
});
};
var handlerB = function () {
@mathisonian
mathisonian / index.md
Last active August 10, 2024 20:59
requiring npm modules in the browser console

demo gif

The final result: require() any module on npm in your browser console with browserify

This article is written to explain how the above gif works in the chrome (and other) browser consoles. A quick disclaimer: this whole thing is a huge hack, it shouldn't be used for anything seriously, and there are probably much better ways of accomplishing the same.

Update: There are much better ways of accomplishing the same, and the script has been updated to use a much simpler method pulling directly from browserify-cdn. See this thread for details: mathisonian/requirify#5

inspiration

var Dialog = React.createClass({
render: function() {
// 1) render nothing, this way the DOM diff will never try to do
// anything to it again, and we get a node to mess with
return React.DOM.div();
},
componentDidMount: function() {
// 2) do DOM lib stuff
this.node = this.getDOMNode();
var Popover = React.createClass({
render: function() {
// break this rendering tree
return null;
},
componentDidMount: function() {
var node = this.node = document.createElement('div');
// append a node to render into later
document.body.appendChild(node);
@ryanflorence
ryanflorence / Dialog.js
Last active January 9, 2021 16:12
React Portal.js
var Dialog = React.createClass({
mixins: [Portal],
createPortal: function() {
this.dialog = $(this.portalNode).dialog({
autoOpen: false,
title: this.props.title,
close: this.props.onClose
}).data('ui-dialog');
},