Skip to content

Instantly share code, notes, and snippets.

@dracon
dracon / fp.js
Created January 17, 2020 07:04 — forked from BretCameron/fp.js
An example of functional programming in JavaScript, featuring compose, pipe, tap and trace functions
/**
* Performs right-to-left composition, combining multiple functions into a single function.
* @function compose
* @param {...Function} args
* @returns {Function}
*/
const compose = (...fns) => x => fns.reduceRight((output, fn) => fn(output), x, fns);
/**
* Performs left-to-right composition, combining multiple functions into a single function. Sometimes called `sequence`. Right-to-left composition is typically known as `compose`.
@dracon
dracon / container.js
Created January 16, 2020 15:24 — forked from BretCameron/container.js
An example container used for functional programming, to help separate impure functions from pure logic.
const isFunction = fn => fn && Object.prototype.toString.call(fn) === '[object Function]';
const isAsync = fn => fn && Object.prototype.toString.call(fn) === '[object AsyncFunction]';
const isPromise = p => p && Object.prototype.toString.call(p) === '[object Promise]';
const tap = f => x => {
f(x);
return x;
};
@dracon
dracon / nginx.conf
Created March 7, 2019 14:35 — forked from mreschke/nginx.conf
Nginx config for multiple laravel sites based on /api/v1 url paths
# This config will host your main [Laravel] GUI application at /, and any additional [Lumen] webservices at /api/v1 and /api/v2...
# This also works perfectly for all static file content in all projects
# This is full of debug comments so you can see how to print debug output to browser! Took me hours to nail this perfect config.
# Example:
# http://example.com - Main Laravel site as usual
# http://example.com/about - Main Laravel site about page as usual
# http://example.com/robots.txt - Main Laravel site static content as usual
# http://example.com/api/v1 - Lumen v1 api default / route
# http://example.com/api/v1/ - Lumen v1 api default / route
@dracon
dracon / project-create.sh
Created February 3, 2019 18:31 — forked from francoisromain/project-create.sh
A bash script to create a Git post-receive hook to deploy after a Git push
#!/bin/bash
# Call this file with `bash ./project-create.sh project-name [service-name]`
# - project-name is mandatory
# - service-name is optional
# This will creates 4 directories and a git `post-receive` hook.
# The 4 directories are:
# - $GIT: a git repo
# - $TMP: a temporary directory for deployment
@dracon
dracon / simple-json-reponse.php
Created July 6, 2018 13:53 — forked from james2doyle/simple-json-reponse.php
A simple JSON response function for PHP. Used in various PhileCMS plugins.
<?php
function json_response($message = null, $code = 200)
{
// clear the old headers
header_remove();
// set the actual code
http_response_code($code);
// set the header to make sure cache is forced
header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
@dracon
dracon / download-file.js
Created June 27, 2018 14:06 — forked from Tomassito/download-file.js
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
link.click();
@dracon
dracon / index.html
Created October 16, 2016 20:26
Simple single page
<header class="top sticky-wrapper">
<ul class="nav">
<li><a href="#sOne">side 1</a></li>
<li><a href="#sTwo">side 2</a></li>
<li><a href="#sThree">side-3</a></li>
<li><a href="#sFour">side-4</a></li>
</ul>
</header>
<section class="wrapper side-1">
<a class="anchor" id="sOne"></a>
@dracon
dracon / Nav button for collabsible (mobile).markdown
Last active June 20, 2016 09:54
Nav button for collabsible (mobile)
@dracon
dracon / README.md
Created September 24, 2015 23:07 — forked from oodavid/README.md
Backup MySQL to Amazon S3

Backup MySQL to Amazon S3

This is a simple way to backup your MySQL tables to Amazon S3 for a nightly backup - this is all to be done on your server :-)

Sister Document - Restore MySQL from Amazon S3 - read that next

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc