Skip to content

Instantly share code, notes, and snippets.

@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>
@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 / 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 / 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 / endler-register-custom-view-tpl.php
Last active October 13, 2015 17:57
Register custom view templates from a module in Drupal 7.
<?php
/**
* Implements hook_theme().
*
* Drupal 7 view template-ing from a module.
*
* @author Justin Endler
*/
function mymodule_theme($existing, $type, $theme, $path) {
$module_path = drupal_get_path('module', 'mymodule');
@justin-endler
justin-endler / endler-d7-feature-branch.sh
Created December 10, 2012 14:46
Sets up Drupal 7 local and remote feature branch.
#!/bin/bash
#
# Sets up a local Drupal 7 environment for working on a feature branch.
#
# @author Justin Endler
#
defaultsettings="http://drupalcode.org/project/drupal.git/blob_plain/HEAD:/sites/default/default.settings.php"
echo -e "\nThis script is D7-specific."
@justin-endler
justin-endler / endler-d7-feature-review.sh
Created December 10, 2012 17:00
Sets up a local Drupal 7 branch review and attempts a merge with a forked-from repo.
#!/bin/bash
#
# Sets up a local Drupal 7 branch review and attempts a merge with a forked-from repo.
#
# @author Justin Endler
#
defaultsettings="http://drupalcode.org/project/drupal.git/blob_plain/HEAD:/sites/default/default.settings.php"
echo -e "\nThis script is D7-specific."
@justin-endler
justin-endler / endler-wordpress-render-media-button.php
Created December 17, 2012 01:00
How to render a media button in WordPress post edit, making it work for WordPress 3.x.
<?php
/**
* This assumes you'll be plugging in to media-upload.php in order to upload a file.
*
* @author Justin Endler
*/
// Get WordPress version.
$version = get_bloginfo('version');
@justin-endler
justin-endler / endler-trim-backups.sh
Last active December 9, 2015 19:38
Set a maximum amount of files and trim to that amount for a particular location.
#!/bin/bash
#
# Trim total files to maxbackups amount.
#
# Cron:
# http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
#
# @author Justin Endler
#