Skip to content

Instantly share code, notes, and snippets.

Carlo Perassi carlok

Block or report user

Report or block carlok

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
@carlok
carlok / line_counter.sh
Created Jul 4, 2019
Counting the number of textual files and their number of lines
View line_counter.sh
find A_LIST_OF_FOLDERS_AND_FILES -type f -exec grep -Iq . {} \; -print | wc -l
# A_LIST_OF_FOLDERS_AND_FILES => use the previous command as: find a b.txt c where a and c are directories or files
for a in $(find src -type f -exec grep -Iq . {} \; -print); do wc -l $a; done | awk '{split($0,a," "); sum += a[1]} END {print sum}'
@carlok
carlok / txt
Last active Jun 6, 2019
languages I used in the last 30 years or so (I might have forgotten a few)
View txt
assembly
awk
bash
basic
c
c#
c++
java
javascript
mql4/mql5
@carlok
carlok / p3in-publish.py
Last active Jun 27, 2019
AMQP Python3 pika 1.0.0 publish/consume examples
View p3in-publish.py
#!/usr/bin/env python
import pika
# At the moment (2019-04-07) the official examples provided by CloudAMQP are not working anymore
# because pika 1.0.0 has changed
# moreover, the official examples are in Python 2
# these examples have a few benefits:
# they work with python3
# they work with pika 1.0.0
# they were tested with amqps
@carlok
carlok / cloudwatch_logger_module.js
Created May 23, 2018
A simple Node.js module for logging on AWS CloudWatch using Winston
View cloudwatch_logger_module.js
"use strict";
let winston = require("winston");
let cloudWatchTransport = require("winston-aws-cloudwatch");
const set = function (options) {
let logger = new winston.Logger({
transports: [
new winston.transports.Console({
timestamp: true,
@carlok
carlok / hapi-awsses.js
Last active Apr 20, 2017
Hapi Plugin AWS SES (Nodemailer Promosificated)
View hapi-awsses.js
'use strict';
const Mailer = require('nodemailer');
const Ses = require('nodemailer-ses-transport');
exports.register = function (server, options, next) {
const sendTextMailPrm = function (to, subject, body) {
const mailOptions = {
from: options.from,
@carlok
carlok / mRandom.js
Last active Mar 27, 2017
Random Bytes Node Module
View mRandom.js
// based on https://blog.tompawlak.org/generate-random-values-nodejs-javascript
const crypto = require('crypto');
function randomValueHex (len) {
return crypto.randomBytes(Math.ceil(len / 2))
.toString('hex') // convert to hexadecimal format
.slice(0, len); // return required number of characters
}
module.exports = {
@carlok
carlok / index.js
Created Mar 18, 2017
Hapi JWT2 working example
View index.js
// references:
// https://github.com/dwyl/hapi-auth-jwt2
// https://github.com/dwyl/hapi-auth-jwt2/issues/222
// testing a not restricted route:
// http -j --verbose GET http://macone:8000/users/public
// testing a restricted route without a valid token:
// http -j --verbose GET http://macone:8000/users/restricted
@carlok
carlok / kcalendar.html
Last active Jan 11, 2017
Angular 1.5 component wrapper of Datepicker Popup (AngularUI/Bootstrap) - Demo
View kcalendar.html
<!doctype html>
<html ng-app="kcalendarApp">
<head>
<link rel="stylesheet" href="./css/bootstrap-3.3.5-dist/css/bootstrap.min.css" />
<script src="./js/jquery-2.1.3.js"></script>
<script src="./js/angular-1.5.0/angular.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<script src="./js/ui-bootstrap-tpls-2.4.0.min.js"></script>
@carlok
carlok / percentile.py
Created Apr 18, 2016
get top percentile values of an array of numbers
View percentile.py
#!/usr/bin/python
import math
percentile = 0.95
# http://sqa.fyicenter.com/Online_Test_Tools/Random_Real_Number_Float_Value_Generator.php
pixel_values = [31.674171850011, -14.601817055329, -50.326219329371, -16.396269623954, 60.024497592015, 9.1736615676739, 15.208291195156, -72.45523509377, -85.000746439726, -49.873983136473, 89.013266951911, 90.902370949905, -40.423479737516, -46.220096055987, -53.861242107865, -80.838195878063, 13.397552791211, -13.217278723279, -3.1931508546449, 5.4144153734829, -71.64644837003, -66.123504455591, -99.949724953312, 36.715438631751, -56.529802065148, -89.545732965393, -52.416536020418, 19.02381212714, 27.063275691617, 33.577258338636, 44.723530160998, -7.7681148545126, -48.941860835529, -43.828084610234, -1.9154353945261, 28.575669211676, -41.679723018346, -90.067412411598, 95.817001923065, 63.608590404067, 71.931231441271, 18.765631420463, -96.782253104387, -56.17893632162, -60.945051574294, -93.087966594846, 50.743922395115, 54.283560244883, 74.524974791892, -48.982292
@carlok
carlok / mbroi.js
Last active Sep 28, 2015
custom Basic ROI (work in progress) for cornerstoneTool
View mbroi.js
(function ($, cornerstone, cornerstoneTools) {
'use strict';
var toolType = 'mBasicRoi';
var configuration = {
mRadius: 15
};
///////// BEGIN ACTIVE TOOL ///////
You can’t perform that action at this time.