Skip to content

Instantly share code, notes, and snippets.

View daniel12fsp's full-sized avatar

Daniel Pereira daniel12fsp

View GitHub Profile
@daniel12fsp
daniel12fsp / index.js
Created August 25, 2018 13:10
Check if props is in nested object
//It's not the best implementation because will iterate over all props.
// If one props is undefined, so it's uncessary evaluate others props
function hasProps(obj, props){
return props.split(".").reduce((result, prop)=> result && result[prop], obj)
}
//Example
/*
const obj = {a:{b:{c:{d:1}}}}
@daniel12fsp
daniel12fsp / index.js
Created September 10, 2018 18:42
Simple Random Id function
function randomId() {
return Math.random(23).toString(26).slice(2);
}
@daniel12fsp
daniel12fsp / SimpleHTTPServer.js
Last active October 25, 2018 16:43
Simple implementation of HTTP in Node
const net = require('net');
const server = net.createServer(function (socket) {
socket.on('data', function (data) {
const header = data.toString();
console.log("--------start request--------");
console.log(header);
console.log("--------end request--------");
let response = "HTTP/1.1 200 OK\r\n";
body = "<h1> HELLO WORLD &#128521; </h1>";
@daniel12fsp
daniel12fsp / SimpleHTTPS_Server.js
Last active October 29, 2018 20:57
Simple HTTPS Server in Node
const tls = require('tls');
const fs = require('fs');
/*
To generate a valid certificate in command line:
openssl req -x509 -newkey rsa:2048 -keyout keytmp.pem -out cert.pem -days 365
openssl rsa -in keytmp.pem -out key.pem
*/
const options = {
@daniel12fsp
daniel12fsp / GetOnlyNumbers.js
Created November 17, 2018 13:11
Get from string only numbers
function getOnlyNumbers(str){
return Array.from(str).filter(Number)
}
console.log(getOnlyNumber("a1b2c")); //  ["1", "2"]
@daniel12fsp
daniel12fsp / range.js
Last active November 25, 2018 13:57
Range like python for javascript =)
const arr = [...Array(5).keys()];
console.log(arr) //[0, 1, 2, 3, 4]
@daniel12fsp
daniel12fsp / base64_to_clipboard.sh
Last active February 26, 2021 02:00
generate Base64 to clipboard
# You will need to install: sudo apt install xclip
base64 file | tr -d '\n' | xclip -sel clip
@daniel12fsp
daniel12fsp / hotspot.sh
Created November 26, 2018 16:40
Create hotspot in command line linux
nmcli device wifi hotspot con-name my-hotspot ssid my-hotspot band bg password 12345678
@daniel12fsp
daniel12fsp / keybindings.json
Created December 4, 2018 15:41
VS code bind shortcut =)
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "f12",
"command": "workbench.action.tasks.runTask",
"args" : "task-deploy"
}
]
@daniel12fsp
daniel12fsp / rename.sh
Created December 20, 2018 12:13
Rename all files ext1 to ext2
find -type f -name '*.jpg' | rename 's/\.jpeg$/.jpg/'