Skip to content

Instantly share code, notes, and snippets.

@JamieMason
JamieMason / average.js
Created July 28, 2011 09:29
Using underscore.js, return the average value from an array of Numbers.
function average (arr)
{
return _.reduce(arr, function(memo, num)
{
return memo + num;
}, 0) / arr.length;
}
@jacmaes
jacmaes / form.php
Last active July 12, 2023 07:58 — forked from somatonic/inputfieldfile-form.php
Processwire: Front-end upload form example using ProcessWire Inputfields #pw
<?php
/**
* Front-end upload form example
* using ProcessWire Inputfields
*/
$sent = false;
$upload_path = $config->paths->assets . "files/.tmp_uploads/";
@chadrien
chadrien / README.md
Last active July 18, 2024 08:31
Debug PHP in Docker with PHPStorm and Xdebug

Debug your PHP in Docker with Intellij/PHPStorm and Xdebug

  1. For your local dev, create a Dockerfile that is based on your production image and simply install xdebug into it. Exemple:
FROM php:5

RUN yes | pecl install xdebug \
&amp;&amp; echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" &gt; /usr/local/etc/php/conf.d/xdebug.ini \
@MauricioMoraes
MauricioMoraes / one_level_flatten.js
Created October 22, 2015 12:00
Javascript Flatten (for one level nested arrays) - Useful for google apps scripts on spreadsheets
// Takes and array of arrays matrix and return an array of elements.
function flatten(arrayOfArrays){
return [].concat.apply([], arrayOfArrays);
}
@jehaby
jehaby / README.md
Last active January 25, 2024 14:43 — forked from chadrien/README.md
Debug PHP in Docker with PHPStorm and Xdebug

Debug your PHP in Docker with Intellij/PHPStorm and Xdebug

  1. For your local dev, create a Dockerfile that is based on your production image and simply install xdebug into it. Exemple:
FROM php:5

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
@chuckreynolds
chuckreynolds / extend-wordpress-user-session.php
Created July 13, 2016 11:16
This will extend the user login session auth cookie (session_tokens row in wp_usermeta) when the user is an Administrator and checks the Remember Me checkbox on login. Needed this for admins only, and all posts out there I found only did it for all users, and current_user_can didn't work so used user_can with ID.
<?php
/**
* Extend expiration length of the auth cookie for Administrators when hey check Remember Me
*
* @param int $expiration Cookie expiration passed by auth_cookie_expiration() hook
* @return int 90 days in seconds
*/
function chuck_extend_admins_login_session( $expiration, $user_id, $remember ) {
if ( $remember && user_can( $user_id, 'manage_options' ) ) {
@aggiedinger
aggiedinger / LeadPages Smooth Scroll
Last active July 6, 2022 08:26
To add a smooth scroll for anchor links
<!-- Smooth Scroll -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "learn") {
// Prevent default anchor click behavior
@rcanepa
rcanepa / routes.js
Last active March 2, 2023 08:29
Private routes with React Router v4
function PrivateRoute ({component: Component, authenticated, ...rest}) {
return (
<Route
{...rest}
render={(props) => authenticated === true
? <Component {...props} />
: <Redirect to={{pathname: '/login', state: {from: props.location}}} />}
/>
)
}
@gaga5lala
gaga5lala / restore_docker_image_tag.sh
Created November 7, 2017 02:04
Restore docker image tag from text file.
# 1. Backup image tags to text file.
# $ docker images --format "{{.Repository}}:{{.Tag}} {{.ID}}" > img_id.txt
#
# 2. Execute clean-docker-for-mac script
# $ bash clean-docker-for-mac.sh $(docker images --format "{{.ID}}" | xargs)
#
# source: https://gist.github.com/MrTrustor/e690ba75cefe844086f5e7da909b35ce#file-clean-docker-for-mac-sh
#
# 3. Execute this script to restore tags from text file.
@li0nel
li0nel / codepipeline.yml
Created February 5, 2018 13:49
CodePipeline
---
AWSTemplateFormatVersion: 2010-09-09
Parameters:
RepositoryBranch:
Type: String
Default: master
Cluster: