Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Loreto Parisi loretoparisi

🎯
Focusing
Block or report user

Report or block loretoparisi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@loretoparisi
loretoparisi / ec2_ip_address_docker_host.js
Created Jun 25, 2019
Get Docker Host IP Address for EC2 instances
View ec2_ip_address_docker_host.js
const cp = require('child_process');
const ec2 = function (callback) {
const URL = 'http://169.254.169.254/latest/meta-data/local-ipv4';
// we make it silent and timeout to 1 sec
const args = [URL, '-s', '--max-time', '1'];
const opts = {};
cp.execFile('curl', args, opts, (error, stdout) => {
if (error) return callback(new Error('ec2 ip error'));
else return callback(null, stdout);
})
@loretoparisi
loretoparisi / dehyphen.py
Last active Jun 5, 2019
De hyphenate a word with hyphens to matched word - Repl: https://repl.it/@loretoparisi/DeHyphen
View dehyphen.py
import re
text = "oh-oh-oh c-c-c-c-come to home today c-c-c-c-come to me fine-tuning"
print(re.sub(r'(\w+(?:-))+(\w+)', '\\2', text))
print(re.sub(r'(?<!\S)(\w{1,3})(?:-\1)*-(\w+)(?!\S)', '\\2', text))
#pattern = r"(?<=-)\w+(?=[^-\w])"
pattern = r"(?<!\S)(\w{1,3})(?:-\1)*-(\w+)(?!\S)"
r = re.compile(pattern, flags=re.I | re.X | re.UNICODE)
@loretoparisi
loretoparisi / longest_subsequence.py
Last active May 30, 2019
Longest Increasing Subsequence with Linear and Bisect (Binary) Search - http://research.variancia.com/unl-aligner/
View longest_subsequence.py
def longest_subsequence_bisect(seq, mode='strictly', order='increasing',
key=None, index=False):
"""
>>> longest_subsequence_bisect([1,2,3,4,5,6,7,2,2,2,2,2,5,1,7,8])
Return the longest increasing subsequence of `seq`.
Parameters
----------
@loretoparisi
loretoparisi / find.js
Last active Apr 30, 2019
Find and Head with Node.js
View find.js
function scanDirStream(needle, params) {
var options = {
// find -type
type: 'f',
// find -name
name: '*',
limit: 100
};
for (var attrname in params) { options[attrname] = params[attrname]; }
return new Promise((resolve, reject) => {
@loretoparisi
loretoparisi / icu4c_macos.sh
Created Apr 29, 2019
Install icu4c on macOS
View icu4c_macos.sh
export ICU_VERSION=63.1
export PYICU_INCLUDES=/usr/local/Cellar/icu4c/63.1/include
export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/63.1/lib
export PYICU_CFLAGS=-std=c++11
pip install pyicu
@loretoparisi
loretoparisi / asyncio_python.py
Created Apr 18, 2019
Python Async Await with AsyncIO
View asyncio_python.py
import asyncio
async def demo():
print("foo")
await asyncio.sleep(5)
return "bar"
def main():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
result = loop.run_until_complete(demo())
@loretoparisi
loretoparisi / awscat.sh
Last active Apr 18, 2019
AWS CAT - Cat a file from Aws Bucket in Bash
View awscat.sh
function __awscat {
if [ "$1x" != 'x' ]; then
aws s3 cp --quiet "$1" /dev/stdout
fi
}
alias awscat='__awscat'
@loretoparisi
loretoparisi / emoticons.js
Created Apr 17, 2019
Node.js JavaScript Emoticons text codes To Icons
View emoticons.js
module.exports = {
100: "💯",
1234: "🔢",
grinning: "😀",
smiley: "😃",
smile: "😄",
grin: "😁",
laughing: "😆",
satisfied: "😆",
sweat_smile: "😅",
@loretoparisi
loretoparisi / emoticons.json
Created Apr 17, 2019
A JSON trivial list of Emoticons
View emoticons.json
{
"100": "💯",
"1234": "🔢",
"grinning": "😀",
"smiley": "😃",
"smile": "😄",
"grin": "😁",
"laughing": "😆",
"satisfied": "😆",
"sweat_smile": "😅",
@loretoparisi
loretoparisi / randomHSVPalette.js
Created Apr 10, 2019
Generate a random HSV palette of non overlapping colors
View randomHSVPalette.js
function randomHSVPalette(options) {
function random(min, max) {
return min + Math.random() * (max - min);
}
function HSVtoXYZ(hsv) {
var h = hsv[0];
var s = hsv[1];
var v = hsv[2];
You can’t perform that action at this time.