Skip to content

Instantly share code, notes, and snippets.

View yaml2json.sh
#!/bin/bash
if [ -z "$1" ]
then
echo "USAGE:"
echo ""
echo "yaml2json.sh file.yaml"
echo ""
echo "it will generate the file.yaml.json"
exit 1
View foreach-array_map.php
<?php
$numbers = \range(0, 100000);
$result = [];
$start = \microtime(true);
foreach ($numbers as $number) {
$result[] = $number * 10;
}
$end = \microtime(true);
@Raffaello
Raffaello / top-k-words-stream.sc
Last active Nov 8, 2018
Top K words with MaxHeap
View top-k-words-stream.sc
val input2 =
"""
|Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum viverra sit amet ligula id imperdiet. Proin vestibulum eget tellus in viverra. Mauris eleifend malesuada nunc, non porta quam placerat non. Nunc viverra, quam ac varius posuere, sapien tortor elementum nibh, a pulvinar mi nulla vitae lorem. Duis diam dolor, luctus ut suscipit eu, sodales in est. Maecenas egestas at velit eleifend laoreet. Aliquam imperdiet lorem et dolor finibus laoreet vel et lectus. Duis finibus felis eu tempus consectetur. Quisque vestibulum metus sed pretium consequat. Sed non quam faucibus, fringilla mi vel, porttitor metus.
|
|Nulla tortor est, dignissim nec orci sit amet, vulputate commodo libero. Integer gravida non turpis malesuada fermentum. Pellentesque sollicitudin sem sed lobortis elementum. Phasellus nec est metus. Integer id vehicula velit, sit amet scelerisque tortor. Nullam fermentum ultricies sodales. Duis vitae elementum diam, sit amet dictum nulla. Cras eu velit aliquam, ven
@Raffaello
Raffaello / vagrant
Last active Apr 10, 2018
vagrant sudoers file
View vagrant
Cmnd_Alias VAGRANT_EXPORTS_CHOWN = /bin/chown 0\:0 /tmp/*
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_EXPORTS_MV = /bin/mv -f /tmp/* /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /usr/bin/systemctl status --no-pager nfs-server.service
Cmnd_Alias VAGRANT_NFSD_START = /usr/bin/systemctl start nfs-server.service
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
Cmnd_Alias VAGRANT_HOSTMANAGER_UPDATE = /bin/cp home/rbertini/.vagrant.d/tmp/hosts.local /etc/hosts
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /*/exports
Cmnd_Alias VAGRANT_EXPORTS_REMOVE_2 = /bin/cp /*/exports /etc/exports
%wheel ALL=(root) NOPASSWD: VAGRANT_EXPORTS_CHOWN, VAGRANT_EXPORTS_ADD, VAGRANT_EXPORTS_MV, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_HOSTMANAGER_UPDATE, VAGRANT_EXPORTS_REMOVE, VAGRANT
View FizzBuzz.sc
(1 to 100).map { x =>
val str = StringBuilder.newBuilder
if(x % 3 == 0) str append "Fizz"
if(x % 5 == 0) str append "Buzz"
if(str.size > 0) str.toString else x.toString
}.mkString("\n")
@Raffaello
Raffaello / mysql_field_type.php
Last active Jan 17, 2018
mysql_field_type comparison with type of msqli
View mysql_field_type.php
<?php
// parameters, set them properly based on your needs.
$host = '';
$username = '';
$password = '';
$query = 'select * from [table] limit 0';
$c = mysql_connect($host, $username, $password);
$r = mysql_query($query, $c);
$n = mysql_num_fields($r);
View ssh_tunnel.sh
#!/bin/bash
ssh -fNL $target_port:$target_host:$source_port $source_host
View puzzle.sc
def reverseInt(x: Int): Int = {
x.toString.reverse.toInt
}
def palindromeNumberEquation(x:Int, y:Int): Boolean = {
reverseInt(x) == x*y
}
def differentDigitsInt(x: Int, y: Int): Boolean = {
x.toString.groupBy(c => c).map(m => m._2.length).sum == y
@Raffaello
Raffaello / clean-backup-logs-file.sh
Last active Nov 10, 2016
log rotation clean up
View clean-backup-logs-file.sh
sudo find /var/log/ -name "*.log.*" -exec rm -v {} \;
@Raffaello
Raffaello / vbox-modprobe.sh
Last active Oct 9, 2017
VirtualBox recompiling kernel with Secure Boot.
View vbox-modprobe.sh
#!/usr/bin/bash
openssl req -new -x509 -newkey rsa:2048 -keyout vbox.keyout -outform DER -out vbox.der -nodes -days 36500 -subj "/CN=VBoxDrv/"
mokutil --import vbox.der
### after the reboot yo are able to add it to the secure boot, please select it.
reboot