Skip to content

Instantly share code, notes, and snippets.

View srt4rulez's full-sized avatar

Jake Dennison srt4rulez

  • HALIGHT, Inc
  • Windsor, ON
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active May 4, 2024 15:48
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@npearce
npearce / install-docker.md
Last active April 19, 2024 12:35
Amazon Linux 2 - install docker & docker-compose using 'sudo amazon-linux-extras' command

UPDATE (March 2020, thanks @ic): I don't know the exact AMI version but yum install docker now works on the latest Amazon Linux 2. The instructions below may still be relevant depending on the vintage AMI you are using.

Amazon changed the install in Linux 2. One no-longer using 'yum' See: https://aws.amazon.com/amazon-linux-2/release-notes/

Docker CE Install

sudo amazon-linux-extras install docker
sudo service docker start
@jasonhofer
jasonhofer / symfony-bare.php
Last active June 22, 2018 18:24
An example of using the core Symfony components outside of a framework.
<?php
//
// Symfony Bare
//
// php -S localhost:8181 symfony-bare.php
//
// http://localhost:8181/is-leap-year
//
require_once 'vendor/autoload.php';
@dunglas
dunglas / example.php
Created April 19, 2018 06:25
A minimalist GraphQL client for PHP
<?php
$query = <<<'GRAPHQL'
query GetUser($user: String!) {
user (login: $user) {
name
email
repositoriesContributedTo {
totalCount
}
@jasonhofer
jasonhofer / simple-http-kernel.php
Last active July 21, 2021 17:22
A simplified version of the Symfony HttpKernel to help show what it does.
<?php
use Psr\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation as Http;
/**
* HttpKernel: "Get the response, and get out."
*
* As soon as the kernel gets its hands on a Response object, it says "I'm done" and returns it.
* It is only interested in finding a Response object, at which point it will call it a day.
@dahjelle
dahjelle / pre-commit.sh
Created July 13, 2016 16:48
Pre-commit hook for eslint, linting *only* staged changes.
#!/bin/bash
for file in $(git diff --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
exit 1 # exit with failure status
fi
done
@efarem
efarem / convert-apache-php-fpm
Created May 24, 2016 15:09
Convert Apache to PHP-FPM
#!/bin/bash
# Install dependencies
sudo apt-get install -y apache2-mpm-worker
sudo apt-get install -y libapache2-mod-fastcgi php5-fpm
# Disable prefork & Enable fcgi
sudo a2dismod php5 mpm_prefork
sudo a2enmod actions fastcgi alias mpm_worker

Automatically Prepend a Jira Issue ID to Git Commit Messages

Use a git hook to match a Jira issue ID from the current branch, and prepend it to every commit message

Assuming the current branch contains a Jira issue ID, you can use a git hook script to prepend it to every commit message.

  1. Create an empty commit-msg git hook file, and make it executable. From your project's root directory:

     install -b -m 755 /dev/null .git/hooks/commit-msg
    
  2. Save the following script to the newly-created .git/hooks/commit-msg file:

@Phoenix2k
Phoenix2k / gist:7980936
Created December 16, 2013 01:12
Convert RGB(A) values to #hexdecimal using jQuery.css()
// Convert RGB(A) values to #hexdecimal using jQuery.css()
// Original: http://jsfiddle.net/DCaQb/
// Note: This will not work on browsers which return 'color names' instead of rgb(a) values (i.e. IE8)
function rgba2hex( color_value ) {
if ( ! color_value ) return false;
var parts = color_value.toLowerCase().match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/),
length = color_value.indexOf('rgba') ? 3 : 2; // Fix for alpha values
delete(parts[0]);
for ( var i = 1; i <= length; i++ ) {
parts[i] = parseInt( parts[i] ).toString(16);
@gerbenvandijk
gerbenvandijk / Mark parent navigation active when on custom post type single page
Last active January 1, 2024 21:22
Mark (highlight) custom post type parent as active item in Wordpress Navigation.When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
<?php
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Get post ID, if nothing found set to NULL
$id = ( isset( $post->ID ) ? get_the_ID() : NULL );