Skip to content

Instantly share code, notes, and snippets.

@xelaz
xelaz / default HTTP
Created November 17, 2022 20:31 — forked from iam-hussain/default HTTP
Serve nextJS app from a port through NGINX reverse proxy HTTP and HTTPS
# Serve nextJS app from a port through NGINX reverse proxy (HTTP)
# Path: /etc/nginx/sites-available/default
# Default server configuration for HTTP
server {
server_name www.DOMAINNAME.com DOMAINNAME.com;
# Serve any static assets with NGINX
location /_next/static {
alias /home/ubuntu/PROJECT_FOLDER/.next/static;
// Wifi Credentials
const WIFI_NAME = "YOURSSID";
const WIFI_PASS = "YOURPASS";
// Your location latitude and longitude
const lat = 'YOURLAT';
const lon = 'YOURLON';
// Required libs
@xelaz
xelaz / .zshrc
Created January 27, 2020 09:36
Zsh prompt with git branch, current node version and .nvmrc version
##### PS1 #######
autoload -U colors && colors
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)/'
}
@xelaz
xelaz / classNames.js
Created January 22, 2020 15:12
Simple class names concatenation in ES6 for React and others
const classNames = (...args) => args.reduce((list, clss) => list.concat(clss).filter(Boolean), [])
.join(' ').trim().replace(/\s{2,}/g, ' ');
const test = null;
const test2 = true;
console.log(classNames(test && 'test1'));
console.log(classNames(test2 && 'test2'));
console.log(classNames(['test1', 'test2', test && 'test3', test2 && 'test4'], 'test5'));
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
@xelaz
xelaz / delete-chunks.js
Created August 22, 2018 07:30
Delete orphaned Chunks from Mongo GridFs
db.getCollection('fs.chunks').aggregate([
{ $lookup: { from: 'fs.files', localField: 'files_id', foreignField: '_id', as: 'file' } },
{ $unwind: { path:'$file', preserveNullAndEmptyArrays: true } },
{ $match: { file: { $exists: false } } },
{ $project: { _id: 1, files_id: 1 } },
]).forEach(function(chunk) {
printjson(chunk);
// db.getCollection('fs.chunks').remove({ _id: chunk._id });
});
@xelaz
xelaz / reset.css
Last active August 21, 2018 08:16
/* custom-reset.css | 20.08.2018 | https://yurch-html.github.io/dist/custom-reset.html */
*,
*:before,
*:after {
box-sizing: inherit;
}
html {
box-sizing: border-box;
@xelaz
xelaz / imageUpload.js
Created June 5, 2018 10:43 — forked from richardzcode/imageUpload.js
Upload image file from Node.js
/**
* Example of simulating file upload post form from node.js
*
* Set your own file and server options.
*/
var img = require('fs').readFileSync('./sample.png');
var options = { host: '...'
, port: ...
@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
@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;
}