Skip to content

Instantly share code, notes, and snippets.

View elvisciotti's full-sized avatar

Elvis Ciotti elvisciotti

View GitHub Profile
@elvisciotti
elvisciotti / cloudflareSecurityLevel.bash
Last active August 14, 2022 06:38
Bash script to change Cloudflare security level via RESTful API. Could be used in a cronjob to disable the website during high load
#!/bin/bash
#
# Toggles cloudflare security_settings base on system load
# Only prints output when the setting is changed to a different one
# Needs "jq" installed
#
# e.g. essentially_off, low, medium, high, under_attack
USERNAME=$1
@elvisciotti
elvisciotti / phpstormRamDiskCreate.bash
Last active August 14, 2022 06:39
Bash script to create ram disk to be used to speed up IntelliJ
#!/bin/bash
ramDiskCreate ()
{
if [ ! -d /Volumes/RAMDisk/intellij-cache/ ]; then
diskutil erasevolume HFS+ 'RAMDisk' `hdiutil attach -nomount ram://1024288`;
else
echo RAMDisk already created;
fi;
mkdir -p /Volumes/RAMDisk/intellij-caches;
@elvisciotti
elvisciotti / treesize.bash
Last active August 14, 2022 06:50
Bash function to display directories from the biggest ones at the top
#/bin/bash
function treesize() {
du -k -d 1 $1 | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
{
u = 1;
while ($1 >= 1024) {
@elvisciotti
elvisciotti / wakeUpSpotify.scpt
Last active September 9, 2018 13:21
Apple script tolaunch spotify and increase volume gradually
# To install as alarm, add this to crontab (crontab -e)
#30 8 * * 1-5 /usr/bin/osascript /Users/elvis/Documents/wakeUpSpotify.scpt
set volume 3
# morning playlist
open location "spotify:user:elvispm83:playlist:5D8fO5FikywbgjOOeICk2e"
delay 5
tell application "Spotify"
set the sound volume to 20
@elvisciotti
elvisciotti / coinMarketCap.googleSpreadsheet.js
Last active August 14, 2022 06:51
Google spreadsheet function to calculate the value of a CryptoCurrency using coinmarketcap API
/**
* Return a cryptocurrency value in USD using coinmarketcap API
*
* @param string currency e.g. BTC, ETH
*
* @return float value
*/
function coinmarketcap(currency)
{
var body = UrlFetchApp.fetch("https://api.coinmarketcap.com/v1/ticker/");
@elvisciotti
elvisciotti / gitcommit.bash
Last active November 13, 2015 16:25
bash function to commit a message prepending the branch name
# gitcommit this message will be commited, with the branch name prepended
# e.g. (on branch feature01)
# > gitcommit this is the commit message
# > Committed with message "feature01 this is the commit message"
gitcommit() {
gm_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p');
gm_commitMessage="${gm_branch} $@"
git commit -m "${gm_commitMessage}"
echo Committed with message \"$(git log -n1 --pretty=format:%s)\"
}
@elvisciotti
elvisciotti / etc-fileline-add.pp
Last active August 29, 2015 14:09
Puppet task to add a line into a file if not existing and not commented out (prefixed with "#")
# add STRING-XXXXXXX to FILE-YYYYYY
# if commented out, it gets re-added
exec { "[task name]":
command => '/bin/echo "STRING-XXXXXXX" >> FILE-YYYYYY',
unless => '/bin/grep -E "^STRING-XXXXXXX$" FILE-YYYYYY'
}
@elvisciotti
elvisciotti / fileUploadMaxSize.js
Last active August 14, 2022 06:25
Attach a "onchange" listener to file upload elements for each form. If the selected file size invalid (bigger than input.MAX_FILE_SIZE, disable submit button and append a message
$(document).ready(function() {
/*
* Attach a "onchange" listener to file upload elements for each form.
* Behaviour:
* If the selected file size invalid (bigger than the value from the <input name="MAX_FILE_SIZE" /> element):
* - disable submit button
* - append a message (class="errors") to the form.
* If the selected file size is valid:
* - enable the submit button
* - remove the error message previously added
@elvisciotti
elvisciotti / cssReload.js
Last active December 29, 2015 17:29
browser toolbar link to reload CSS using JavaScript
javascript:var links=document.getElementsByTagName("link"); for (var i = 0; i < links.length;i++) { var link = links[i]; if (link.rel === "stylesheet") {link.href += "?"; }}; return false
@elvisciotti
elvisciotti / gist:7467264
Last active August 14, 2022 06:27
chrome launch without web security, custom user agent, data dir and web page
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome" --disable-web-security --user-agent="Android"  --user-data-dir="C:/temp-chrome-app" --app=file:///C:/path/to/app.html"