Skip to content

Instantly share code, notes, and snippets.

@laurenashpole
laurenashpole / laurenashpole.com.conf
Created October 13, 2021 21:24
Basic Nginx Configuration with Caching
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;
font/ttf max;
font/opentype max;
application/font-woff max;
font/woff2 max;
@laurenashpole
laurenashpole / lodash-imports-codemod.js
Last active March 26, 2023 10:38
A jscodeshift codemod for converting any Lodash imports into direct imports
export default (fileInfo, api) => {
const j = api.jscodeshift;
const root = j(fileInfo.source);
let specifiers = [];
root
.find(j.ImportDeclaration, isLodashImport)
.forEach((path) => specifiers.push(...path.node.specifiers.map((specifier) => specifier.local.name)))
.remove();
@laurenashpole
laurenashpole / will_paginate_helper.rb
Created February 7, 2019 02:37
A Rails helper for using render_to_string with will_paginate
module WillPaginateHelper
class StringLinkRenderer < WillPaginate::ActionView::LinkRenderer
protected
def url(page)
@base_url_params ||= begin
url_params = merge_get_params(default_url_params)
url_params[:only_path] = true
merge_optional_params(url_params)
end
@laurenashpole
laurenashpole / assets.js
Created September 25, 2018 21:30
A custom Swig tag for getting versioned asset paths.
let assets = require('../../public/assets.json');
module.exports = function (swig) {
swig.setTag('asset', _parse, _compile, false, true);
};
let _parse = function (str, line, parser) {
parser.on('*', function (token) {
let match = token.match.match(/^["'](.*?)["']$/);
let assetPath = match ? match[1] : null;