Skip to content

Instantly share code, notes, and snippets.

View codfish's full-sized avatar

Chris O'Donnell codfish

View GitHub Profile
@codfish
codfish / remove-duplicates.js
Last active November 20, 2018 03:55
Remove duplicate values from an array by converting it to a Set, then back to an array.
[...new Set([].concat(...arrayName))]
@codfish
codfish / Dockerfile
Last active February 20, 2019 18:03
Example json-server module for marketing campaigns. `json-server api.js`
FROM mhart/alpine-node:11.10
RUN mkdir /app
WORKDIR /app
COPY ./package.json ./package-lock.json ./
RUN npm install
EXPOSE 4000
CMD npm run dev
@codfish
codfish / swagger.yml
Created April 3, 2018 13:32
Example swagger 2.0 doc with extensive use of reusable definitions, responses & parameters.
swagger: '2.0'
info:
version: '0.0.1'
title: Marketing Campaign API
host: api.example.com
basePath: /v1
@codfish
codfish / htmlentity.js
Created February 28, 2018 14:24 — forked from CatTail/htmlentity.js
Javascript: encode(decode) html text into html entity
// encode(decode) html text into html entity
var decodeHtmlEntity = function(str) {
return str.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
});
};
var encodeHtmlEntity = function(str) {
var buf = [];
for (var i=str.length-1;i>=0;i--) {
@codfish
codfish / xdebug-hack.md
Last active December 19, 2017 16:14
Xdebug Hack

Xdebug tends to slow down a lot of things. Here's a hack to unload the extension by default but load it whenever it's needed (for instance, when generating php code coverage.

Prevent Xdebug from loading by default

If you use brew to install php 7, should be here: /usr/local/etc/php/<version>/conf.d/ext-xdebug.ini. Edit that file (replacing <version> with whatever version of php you're using) and comment out the line that begins with zend_extension. The code examples here assume 7.0.

;zend_extension="/usr/local/opt/php70-xdebug/xdebug.so"
@codfish
codfish / .php_cs.dist
Last active July 6, 2023 19:12
PHP-CS-Fixer configuration file. PSR-2 plus some opinionated options to make code cleaner.
<?php
/**
* Rules we follow are from PSR-2 as well as the rectified PSR-2 guide.
*
* - https://github.com/FriendsOfPHP/PHP-CS-Fixer
* - https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
* - https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/PSR-2-R-coding-style-guide-additions.md
*
* If something isn't addressed in either of those, some other common community rules are
@codfish
codfish / index.html
Last active November 20, 2017 17:50
AngularJS 1.x Slick Carousel Directive
<div class="slick-slider clearfix"
data-slick-carousel
data-slides="gallery.slides"
data-interstitial="gallery.interstitial"
data-settings="{}"
data-active="gallery.active"
data-onchange="gallery.onAfterChange"
data-count="gallery.slides.length"
data-interstitial-link="gallery.interstitial.link"
data-autoplay="true"
@codfish
codfish / app-controller.js
Created November 20, 2017 17:41
AngularJS 1.X Meta Service
/**
* Application Controller
*
* @ngInject
*/
function AppCtrl($rootScope, $log, $state, MetaService, configuration) {
$rootScope.$on('$stateChangeSuccess', function(event, state, params, from, fromParams) {
// set canonical based on the new state url & param values
MetaService.canonical = configuration.DOMAIN_HOST + $state.href(state, params);
});
@codfish
codfish / no-js-no-styles.scss
Last active September 21, 2017 13:20
Remove site styles when js is not supported
// when using modernizr or similar
.no-js body * {
display: initial !important;
opacity: 1 !important;
visibility: visible !important;
overflow: visible !important;
transform: none !important;
float: none !important;
position: static !important;
height: auto !important;
@codfish
codfish / reference.md
Last active April 11, 2024 19:18
Dev Resources & Reference

Here are some sites with useful developer tools & reference material. Some of them are simple links to the original source, while some are also elaborated on below for quick & helpful reference.

  • Fauna: The database built for serverless, featuring native GraphQL -- Source
  • Upstash: Another database service built for serverless, specifically focused on Redis, but also featuring GraphQL -- Source
  • Cloudinary: Store, transform, optimize, and deliver all your media assets with easy-to-use APIs, widgets, or user interface. -- Source
  • Mailtrap.io: Safe Email Testing for Staging & Development. -- Source
  • k6: Open source load testing tool and SaaS for engineering teams. -- Source
  • Algolia: Rapidly create and scale AI-powered search and discovery across websites and applications. Algolia is fast, customizable and secure. -- Source
  • **S