Skip to content

Instantly share code, notes, and snippets.

@necolas
necolas / using-OnLayout.js
Last active September 23, 2020 09:16
React Pressable / OnLayout
/**
* OnLayout is built upon: View (and ResizeObserver), StyleSheet
*/
const elementBreakpoints = {
small: { minWidth: 200 },
medium: { minWidth: 300 }
large: { minWidth: 500 }
};
@vlucas
vlucas / encryption.js
Last active April 2, 2024 14:26
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@necolas
necolas / webpack-pre-css-loader.js
Created September 8, 2014 20:15
webpack-pre-css-loader.js
var path = require('path');
/**
* CSS transform dependencies
*/
var autoprefixer = require('autoprefixer-core');
var calc = require('rework-calc');
var color = require('rework-color-function');
var conformance = require('rework-suit-conformance');

Currently you can export things from a module in at least six different ways, and import things in at least six different ways, resulting in 36 different combinations, most of which are not semantically valid.

Here is a greatly simplified (and probably naive) suggestion for modules in ES6:

###export You can only export named things, including variables and functions.

let a = "hello";
export a;
@domenic
domenic / .bashrc
Last active September 1, 2015 17:50
.bashrc with GitHub PR function
pr () {
git fetch origin refs/pull/$1/head:refs/remotes/origin/pr/$1 --force
git checkout -b pr/$1 origin/pr/$1
git rebase master
git checkout master
git merge pr/$1 --ff-only
}

Today I had a brief debate on twitter about AMD vs CommonJS, https://twitter.com/TechWraith/status/441387541778808832. It's a debate worth having for sure. But I had to bail out of this one. The thing that annoyed me is that the first argument that people bring up to disquality AMD is "the syntax is too complex". I disagree with this. There are lots of reasons to prefer CommonJS over AMD, but the module authoring syntax is not a very good one. There was also a related statement that AMD authoring introduces more "cognitive overhead". This is absolutely true. But I don't consider this to be synonymous with "complexity" by any means.

So I thought I'd explore some comparable examples. Here's a simple one that was offered up by someone else in the thread. This was on twitter so I can forgive erring on the side of brevity.

AMD

define('myThing', ['some', 'deps'], function (some, deps) {
  //my code
  
 return myThing;
@roberttod
roberttod / cookie-blocking-test.js
Created October 10, 2013 10:29
Test if the cookie is locked during synchronous execution.
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active March 15, 2024 11:26
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@ryanflorence
ryanflorence / package.json.md
Last active December 23, 2015 02:29
Lets make a better package.json

A better package.json

Right now everybody seems to be creating their own .json.

Here are the reasons I think it happens:

  1. node dependencies may be different than browser dependencies
  2. node main.js may be different than browser main.js
  3. {project} {something} may be different than {project2} {something2}
@ragingwind
ragingwind / Backend Architectures Keywords and References.md
Last active April 17, 2024 10:51
Backend Architectures Keywords and References