Skip to content

Instantly share code, notes, and snippets.

View kopiro's full-sized avatar

Flavio Maria De Stefano kopiro

View GitHub Profile
@kopiro
kopiro / backup-repos.sh
Last active October 15, 2018 10:39
Backup all Repositories in current directory
backup-repos() {
for i in $(find . -type d -maxdepth 1 -mindepth 1); do
echo "Looking in $i..."
if [ -d "$i/.git" ]; then
echo "Found repository in $i, init backup..."
pushd $i > /dev/null
zip_name="$i-$(date +'%y%m%d').zip"
zip_path="/opt/backups/$zip_name"
echo "ZIP path: $zip_path"
if [ ! -f "$zip_path" ]; then
@kopiro
kopiro / number_to_english.js
Created September 7, 2018 12:55
Number to English
const digit_to_string = {
0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
@kopiro
kopiro / README.md
Created June 22, 2018 11:48
Download entire INTERNET

Internet Downloader

Simple POC

Compilation

brew install wget
gcc -lcurl download_internet.c
@kopiro
kopiro / number-generator.php
Created June 13, 2018 16:18
PHP Number Generator
<?php
function autoIncrement($start = 0, $step = 1, $circle = -1, $repeat = 1) {
$i = $start;
while (true) {
for ($j = 0; $j < $repeat; $j++) yield $i;
$i += $step;
if ($i === $circle) $i = $start;
}
}
@kopiro
kopiro / Dockerfile OCI8
Created May 24, 2018 09:58
Dockerfile-oci8
FROM php:7.1-fpm
RUN set -ex && \
apt-get update && \
apt-get -y --no-install-recommends install \
apt-utils \
unzip \
nano \
git
@kopiro
kopiro / aws-say.js
Created April 24, 2018 14:14
Convert text to mp3 using AWS Polly
const aws = require('aws-sdk');
aws.config.loadFromPath('aws.json');
const locale = 'it-IT';
const fs = require('fs');
const pollyClient = new aws.Polly({
signatureVersion: 'v4',
region: 'eu-west-1'
@kopiro
kopiro / ImplicitGrantWithPostmessage.php
Created April 12, 2018 08:03
Implicit Grant with Postmessage for Laravel Passport
<?php
namespace App\Libraries\OAuth;
class ImplicitGrantWithPostmessage extends \League\OAuth2\Server\Grant\ImplicitGrant
{
public function completeAuthorizationRequest(\League\OAuth2\Server\RequestTypes\AuthorizationRequest $authorizationRequest) {
$response = parent::completeAuthorizationRequest($authorizationRequest);
$reflectionClassResponse = new \ReflectionClass($response);
@kopiro
kopiro / README.md
Last active April 10, 2022 20:57
Execute sudo commands asking password interactively via macOS security dialog only one time

sudoize.sh

Asks for admin privileges via macOS security dialog and writes in the /etc/sudoers file this string:

youruser ALL=(ALL) NOPASSWD:ALL

allowing you to execute next sudo commands without asking for password via terminal.

@kopiro
kopiro / monitor-alpine.sh
Last active March 18, 2021 12:12
Monitor directory change and execute a command
#!/bin/sh
while (true); do
inotifywait . -m -r -e create -e modify -e move -e delete
./execute-command.sh
done
@kopiro
kopiro / spotify-castv2-client-example.js
Last active November 27, 2020 11:31
Spotify CastV2 Client example
const Client = require('castv2-client').Client;
const Spotify = require('./Spotify');
const mdns = require('mdns');
const browser = mdns.createBrowser(mdns.tcp('googlecast'));
browser.on('serviceUp', function(service) {
console.log('found device "%s" at %s:%d', service.txtRecord.fn, service.addresses[0], service.port);
if (service.txtRecord.fn === process.env.SPOTFIY_DEVICE) {
ondeviceup(service.addresses[0], service.txtRecord.fn);