Skip to content

Instantly share code, notes, and snippets.

@justin-endler
justin-endler / mvd.sh
Last active September 5, 2018 17:55
mv to destination, same name
#!/bin/bash
# get source and destination parent
if [[ -z $1 ]]; then
echo "source and destionation parent arguments required"
exit 1
fi
SOURCE=$1
DESTINATION_PARENT=~/Documents/bb-bk-00
@justin-endler
justin-endler / javascript.json
Last active April 4, 2018 01:06
VS Code JavaScript User Snippet
{
"Test flag": {
"prefix": "test",
"body": [
"// @test"
],
"description": "Flag line as testing only"
},
"Todo flag": {
"prefix": "todo",
@justin-endler
justin-endler / findSelectors.js
Last active March 13, 2017 21:26
Find css selectors in js file
'use strict';
const file = 'some_file.js';
const ignore = [
'a',
'input',
'span',
'td',
'title',
@justin-endler
justin-endler / cp_branch.sh
Created April 20, 2016 13:30
copy current git branch to clipboard
echo -n "$(git rev-parse --abbrev-ref HEAD)" | pbcopy
@justin-endler
justin-endler / mobile-width-helpers.js
Last active October 14, 2016 15:10
Mobile Width Problem Helpers
// not for production use
function MobileWidthHelpers () {
this.stringName = stringName;
var ignoreElements = [
'SCRIPT',
'LINK',
'META'
];
function stringName ($el) {
@justin-endler
justin-endler / indefinite_mutation_observer.js
Last active October 4, 2016 13:43
MutationObserver: Listen Indefinitely On Changing Element
// support multiple browsers
// http://stackoverflow.com/questions/2844565/is-there-a-jquery-dom-change-listener/11546242#11546242
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var elementId = 'some-id';
// instantiate initial observer
var observer = new MutationObserver(observeIndefinitely(elementId));
observer.observe(document.getElementById(elementId), {
// expensive, only use what's needed of these
attributes: true,
childList: true,
@justin-endler
justin-endler / nodejs-express-request-proxy-response-cookies.js
Created August 14, 2015 18:11
node.js express request Proxy Response Cookies
// where res is the Express res
// where response is the request module response
// assumes Lodash or Underscore is present
function proxyResponseCookies (res, response) {
var setCookie = response.headers['set-cookie'];
if (setCookie) {
_.each(setCookie, function (cookie) {
var name;
var value;
@justin-endler
justin-endler / request_module_poodle.md
Last active August 29, 2015 14:16
Node.js request module and POODLE

openssl thrown in the callback of a node.js request module request:

error: Error: 140735274562320:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:1293:SSL alert number 40

    at SlabBuffer.use (tls.js:235:18)
    at CleartextStream.read [as _read] (tls.js:455:29)
    at CleartextStream.Readable.read (_stream_readable.js:341:10)
    at EncryptedStream.write [as _write] (tls.js:369:25)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
@justin-endler
justin-endler / routes.js
Created October 17, 2014 14:14
How to bail on an Express route based on some criteria
// Premise:
// Your app interacts with some data resource.
// There is a route registered per resource type.
// After requesting a resource of a certain type, it's possible for the data to be of another type.
// E.g. You're requesting a category from an API but you are served a member of that category
// instead because there is only one member in the category.
// this route catches all incoming category requests
app.get(
'/category/:category_id',
@justin-endler
justin-endler / write.snippet
Last active August 29, 2015 14:02
Write File snippet
<snippet>
<content><![CDATA[
(function(n,c){require('fs').writeFile('/somePath/'+n+'.html',c);})('${1:c}',${1}); // @test
]]></content>
<tabTrigger>write</tabTrigger>
<description>fs.writeFile()</description>
<scope>source.js</scope>
</snippet>