Skip to content

Instantly share code, notes, and snippets.

View danielo515's full-sized avatar
🏠
Working from home

Daniel Rodríguez Rivero danielo515

🏠
Working from home
View GitHub Profile
@danielo515
danielo515 / create-gh-labels.js
Created July 12, 2017 07:10
Creates one label on github per package on a lerna repository
#!/usr/bin/env node
'use strict';
/**
* This script creates labels at github.
* It depends on github-api and yargs packages, so make sure you have them installed
* on the environment you are going to run this.
* It accepts a github token or a combination of username and password for auth.
* The token can also be provided as an environment variable.
* To display help just run it with the -h or --help flag.
*
@danielo515
danielo515 / list_packages.js
Created July 12, 2017 06:44
List all packages under a lerna repository
'use strict';
const Fs = require('fs');
const ReadDir = Fs.readdirSync;
const Stat = Fs.statSync;
module.exports = (basePath) => {
const getAllPackages = () => ReadDir(basePath)
.map((d) => `${basePath}/${d}`)
'use strict';
const Urls = ['www.google.es','www.google.com','www.google.it','www.google.de','www.google.no'];
const extension = (joi) => ({
base: joi.string(),
name: 'url',
language: {
metrics: 'needs to be one of {{urls}}'
},
@danielo515
danielo515 / clearEmpties.js
Last active June 9, 2017 13:38
A function that deletes empty object properties (null or undefined) and also deletes empty objects recursively. It is a small modification from https://stackoverflow.com/a/42736367/1734815
function valid(x){
return !( x == null || Number.isNaN(x));
}
function clearEmpties(o) {
for (const k in o) {
if (!valid(o[k])) {
delete o[k];
continue;
}
if (typeof o[k] !== 'object') {
@danielo515
danielo515 / clearEmpties
Created June 8, 2017 16:28
A function that deletes empty object properties (null or undefined) and also deletes empty objects recursively.
function clearEmpties(o) {
for (const k in o) {
if (o[k] == null) {
delete o[k];
continue;
}
if (typeof o[k] !== 'object') {
continue;
}
@danielo515
danielo515 / axios-set-base-path.js
Last active April 29, 2017 12:59 — forked from srph/set-base-path.js
axios: Configure the base path with interceptors
var axios = require('axios');
var join = require('url-join');
// https://github.com/sindresorhus/is-absolute-url/blob/master/index.js#L7
var isAbsoluteURLRegex = /^(?:\w+:)\/\//;
axios.interceptors.request.use(function(config) {
// Concatenate base path if not an absolute URL
if ( !isAbsoluteURLRegex.test(config.url) ) {
config.url = join('http://my-api.com', config.url);

Installation

1)

brew install nginx
sudo cp /usr/local/Cellar/nginx/1.8.0/homebrew.mxcl.nginx.plist /Library/LaunchAgents

2)

Replace /usr/local/etc/nginx/nginx.conf with the nginx.conf in this gist. I'm using port 5000 for my current project. Obviously, change server_name as well, and probably the name of its access log.

@danielo515
danielo515 / CrytoJS_GUUID_test.js
Last active December 14, 2016 16:25
A small benchmark to check if Crypto JS is able to generate GUUID
const CryptoJS = require("crypto-js");
const _ = require('lodash');
let i = 5000;
const keys = [];
console.time('Generating keys');
while(--i)
keys.push(CryptoJS.lib.WordArray.random(128 / 8).toString(CryptoJS.sha256));
i = 5000
while(--i)
keys.push(CryptoJS.lib.WordArray.random(128 / 8).toString(CryptoJS.sha256));
@danielo515
danielo515 / 100-sdflash.rules
Last active August 12, 2016 13:34
Flash an image on sd insertion
# place this at /etc/udev/rules.d/100-sdflash.rules
ACTION=="add", SUBSYSTEM=="usb", DRIVER=="usb", NAME="MyCard" RUN+="/bin/dd bs=1M if=/path/to/image of=/dev/MyCard && echo Flash is complete!"