Skip to content

Instantly share code, notes, and snippets.

View tylerlwsmith's full-sized avatar

Tyler Smith tylerlwsmith

View GitHub Profile
@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

@wkw
wkw / jqChangeElementType.js
Last active May 30, 2020 05:04
jQuery Change Element Type usage: $("span").changeElementType("div")
// from Andrew Whitaker and Jazzbo, http://stackoverflow.com/a/15554920/161625
$.fn.changeElementType = function(newType) {
var newElements = [];
$(this).each(function() {
var attrs = {};
$.each(this.attributes, function(idx, attr) {
attrs[attr.nodeName] = attr.nodeValue;
});
@Integralist
Integralist / Strategy.js
Created June 8, 2013 20:16
Strategy Design Pattern in JavaScript
// Greeter is a class of object that can greet people.
// It can learn different ways of greeting people through
// 'Strategies.'
//
// This is the Greeter constructor.
var Greeter = function(strategy) {
this.strategy = strategy;
};
// Greeter provides a greet function that is going to
@willurd
willurd / web-servers.md
Last active August 15, 2025 21:37
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@luetkemj
luetkemj / wp-query-ref.php
Last active July 30, 2025 04:52
WP: Query $args
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/
@gunderwonder
gunderwonder / wp_post_iterator.php
Created November 6, 2011 17:28
WordPress post iterator
<?php
/* Iterator for arrays of WordPress posts or `WP_Query`.
*
* Simplifies "the loop" by automatically handling the `$post` global for each iteration
* (calling `the_post()`, `setup_postdata()` etc.) and makes sure to reset the global state when the loop has finished.
*
* Usage:
* Loop over ten last posts:
* <?php foreach (new WPQueryIterator(array('post_type' => 'post', 'posts_per_page' => 10)) as $i => $p): ?>
* <?php the_title(); ?>
@mathewbyrne
mathewbyrne / slugify.js
Created October 12, 2011 04:34
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}