Skip to content

Instantly share code, notes, and snippets.

@xelaz
xelaz / Module.php
Last active August 29, 2015 14:09 — forked from noopable/Module.php
<?php
namespace Application;
use Locale;
use Zend\EventManager\Event;
use Zend\ModuleManager\Feature;
class Module implements
Feature\BootstrapListenerInterface
{
@xelaz
xelaz / prodebug.js
Created October 21, 2015 14:54
Debug Function call on objects
var Person = function(location) {
this.location = location;
};
Person.prototype.goto = function() {
console.log('goto: ', this.location);
};
prodebug(Person);
@xelaz
xelaz / .bashrc
Last active November 12, 2019 17:02
My Console PS1 with current node + .nvmrc + git branch
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/->(\1)/'
}
check_node() {
diff <(node -v 2> /dev/null) <(cat .nvmrc 2> /dev/null) | sed -e "/^[^>*]/d" -e 's/>.* \(.*\)/>\1</'
}
current_node() {
node -v 2> /dev/null | sed 's/\(.*\)/->(\1)/'
}
export PS1="[\[\e[31;1m\]\u\[\e[0m\]\[\e[35m\]@\[\e[0m\]\[\e[33m\]\h\[\e[0m\]:\[\e[36;1m\]\w\[\e[0m\]]\[\e[1;31m\]\$(check_node)\[\e[0m\]\[\e[1;34m\]\$(current_node)\[\e[0m\]\[\e[32m\]\$(parse_git_branch)\[\e[0m\]\n\[\e[1;32m\]\\$\[\e[0m\] "
@xelaz
xelaz / dev.conf
Created January 21, 2016 22:30 — forked from scragg0x/dev.conf
Nginx proxy for Vagrant 80 to 8080
server {
listen 80;
server_name *.dev;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
@xelaz
xelaz / vagrant-clean.sh
Created January 28, 2016 15:08 — forked from jdowning/vagrant-clean.sh
Script to clean up Ubuntu Vagrant box before packaging
#!/bin/bash
# This script zeroes out any space not needed for packaging a new Ubuntu Vagrant base box.
# Run the following command in a root shell:
#
# bash <(curl -s https://gist.github.com/justindowning/5670884/raw/vagrant-clean.sh)
function print_green {
echo -e "\e[32m${1}\e[0m"
}
@xelaz
xelaz / resize.js
Last active September 5, 2022 07:27
NodeJs resize and optimize images with sharp
const fs = require('fs');
const glob = require('glob');
const sharp = require('sharp');
const Promise = require('bluebird');
const successList = [];
const errorList = {};
glob("wp-content/uploads/**/*.+(jpeg|jpg)", function (er, files) {
Promise.resolve(files)
@xelaz
xelaz / graphql-apollo-file-upload.js
Last active February 26, 2018 17:12
Upload Files in Mocha with GraphQL
const boundary = '----' + Math.random();
const data = [
'--' + boundary,
'Content-Disposition: form-data; name="operations"',
'\r\n',
'{"query":"mutation($file: Upload!){uploadImage(file:$file){id,uuid}}"}',
'--' + boundary,
'Content-Disposition: form-data; name="map"',
'\r\n',
'{"0":["variables.file"]}',
@xelaz
xelaz / javascript-canvas-sharpen.js
Created March 1, 2018 17:09 — forked from mikecao/javascript-canvas-sharpen.js
Javascript function for sharpening images.
function sharpen(ctx, w, h, mix) {
var x, sx, sy, r, g, b, a, dstOff, srcOff, wt, cx, cy, scy, scx,
weights = [0, -1, 0, -1, 5, -1, 0, -1, 0],
katet = Math.round(Math.sqrt(weights.length)),
half = (katet * 0.5) | 0,
dstData = ctx.createImageData(w, h),
dstBuff = dstData.data,
srcBuff = ctx.getImageData(0, 0, w, h).data,
y = h;
@xelaz
xelaz / resize_preview.html
Created March 2, 2018 17:03 — forked from mfyz/resize_preview.html
HTML5 FileReader + canvas resizer to resize & preview before upload an image using jquery.
<!DOCTYPE html>
<html>
<head>
<title>Angular HTML5 Preview, Crop And Upload</title>
<style>
body {
padding: 50px;
font: 16px Helvetica;
}
@xelaz
xelaz / ElastisearchIngestExample.md
Created May 8, 2018 09:31 — forked from qoomon/ElastisearchIngestExample.md
Elasticsearch auto generated timestamps

PUT _ingest/pipeline/timestamp

{
    "description": "Adds a timestamp field at the current time",
    "processors": [
        {
            "set": {
                "field": "@timestamp",
                "value": "{{_ingest.timestamp}}",
 "override": false