Skip to content

Instantly share code, notes, and snippets.

View ellefsen's full-sized avatar

Kim Ellefsen ellefsen

View GitHub Profile
@mkjiau
mkjiau / axios-interceptors-refresh-token.js
Last active March 13, 2024 10:59
Axios interceptors for token refreshing and more than 2 async requests available
let isRefreshing = false;
let refreshSubscribers = [];
const instance = axios.create({
baseURL: Config.API_URL,
});
instance.interceptors.response.use(response => {
return response;
}, error => {
@DiederikvandenB
DiederikvandenB / nuxt.config.js
Created October 16, 2017 10:21
NuxtJS Sentry Module
module.exports = {
/* ... */
modules: [
['~/modules/sentry', {
public_key: '',
private_key: '',
project_id: '',
}],
],
/* ... */
@adampatterson
adampatterson / Handler.php
Last active April 23, 2019 12:36
Laravel 5.2 custom 500 error page
# /app/Exceptions/Handler.php
# use Symfony\Component\Debug\Exception\FlattenException;
# public function render($request, Exception $e)
$exception = FlattenException::create($e);
$statusCode = $exception->getStatusCode($exception);
if ($statusCode === 404 or $statusCode === 500 and app()->environment() == 'production') {
@kirkbushell
kirkbushell / Interceptor.js
Created January 7, 2016 22:41
Handling JWT, Vue JS and token refreshes
import Unauthorised from './Unauthorised'
export default function() {
return {
response: function(response) {
switch (response.status) {
case 401: return Unauthorised.handle();
}
return response;
@gwillem
gwillem / magento-nginx.conf
Last active July 29, 2023 10:13
Battle-tested Nginx configuration for Magento (source: www.hypernode.com)
# This is an annotated subset of the Nginx configuration from our Magento production platform @ www.hypernode.com
# See https://www.byte.nl/blog/magento-cacheleak-issue
# !!!! If you are a Hypernode customer, do not use this config as it will result in duplicate statements. !!!!!
user app;
worker_processes 4;
pid /var/run/nginx.pid;
events {
@jussi-kalliokoski
jussi-kalliokoski / draw-waveform.js
Created September 24, 2014 06:41
Waveform drawing
function getAudioData (url, time) {
return new Promise(function (resolve, reject) {
var context = new AudioContext();
var track = new Audio(url);
var bufferLength = time * context.sampleRate;
var buffer = new Float32Array(bufferLength);
var collector = context.createScriptProcessor(0, 1);
var audioSource = context.createMediaElementSource(track);
var samplesCollected = 0;
@sahilsk
sahilsk / ELK Procedure
Created August 26, 2014 04:53
nginx proxy configuration for elasticsearch
## Install Docker
```
# install the backported kernel
$ sudo apt-get update
$ sudo apt-get install linux-image-generic-lts-raring linux-headers-generic-lts-raring
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
$ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
@rileypaulsen
rileypaulsen / functions.php
Created August 19, 2014 16:08
Add Advanced Custom Fields Fields to the WP REST API
function wp_api_encode_acf($data,$post,$context){
$data['meta'] = array_merge($data['meta'],get_fields($post['ID']));
return $data;
}
if( function_exists('get_fields') ){
add_filter('json_prepare_post', 'wp_api_encode_acf', 10, 3);
}
-- delete any usermeta specific to the other subsites
delete from wp_usermeta where meta_key regexp '^wp_([0-9]+)_';
-- duplicate the wp_usermeta structure in a working data table,
-- but add a unique index for filtering out duplicates
create table _fix_usermeta like wp_usermeta;
alter table _fix_usermeta add unique(user_id, meta_key);
-- copy the site-specific usermeta, keeping only the last of each duplicate
insert into _fix_usermeta
@tillsanders
tillsanders / intro.markdown
Last active June 24, 2021 20:17
Laravel: drag-and-drop repositioning with auto-save of DB entries

Laravel: drag-and-drop repositioning with auto-save of DB entries

Use case: Database entries are represented in a table. By grabbing and moving a row up or down the table, you can change the entries' order/position. The changes are submitted automatically via ajax.

  • Uses jQueryUI (custom download: sortable is needed)
  • newly created elements are added to the top (see route /jobs/create)