Skip to content

Instantly share code, notes, and snippets.

@peppeocchi
peppeocchi / deploy.yml
Created January 20, 2022 09:04
Github action to deploy private repo on DigitalOcean
name: CI
on:
push:
branches: [ master ]
jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
@peppeocchi
peppeocchi / cronjob.py
Created July 27, 2017 10:09
Simple Aws Lambda script to trigger cronjobs via HTTP
import urllib2
def cronjob_handler(event, context):
url = 'http://mywebsite.com/schedules?authtoken=someRandomString'
urllib2.urlopen(url).read()
@peppeocchi
peppeocchi / latency.sh
Created March 2, 2017 09:50
Measure the first byte response to determine if one or more backend web application servers are experiencing high latency
# Replace "http://www.example.com" before running this command
for X in 'seq 60'; do curl -Ik -w "HTTPCode=%{http_code} TotalTime=%{time_total}\n" http://www.example.com/ -so /dev/null; done
@peppeocchi
peppeocchi / script.sh
Created March 2, 2017 09:46
Display the number of Apache processes and the total RAM used, in a tablular format that updates every second
watch -n 1 "echo -n 'Apache Processes: ' && ps -C apache2 --no-headers | wc -l && free -m"
@peppeocchi
peppeocchi / remove_non_ascii.php
Created February 2, 2017 11:17
Remove non-ASCII chars from string
<?php
function removeNonAscii($string) {
$regex = "/[^\x{0000}-\x{007F}]+/";
return preg_replace($regex, '', $string);
}
@peppeocchi
peppeocchi / update-eb.sh
Created January 16, 2017 11:11
Update awsebcli (eb) without getting an error
# you may not need to run it with sudo
sudo pip install --ignore-installed --upgrade awsebcli
@peppeocchi
peppeocchi / labinput.js
Last active January 11, 2017 16:32
Bootstrap form inputs clearable with embedded labels
var LabInput = {
refresh() {
setTimeout(() => {
$('.labinput').each(function () {
let label = $('label', this),
input = $('input', this);
// Check if it has a clearable class
if ($(this).hasClass('clearable')) {
let x = $(`<div class="clear-input">&times;</div>`);
# After updating OS X (from 10.10 to 10.11), MAMP didn't started the apache server (complaining apache was already running)
# The solution found on the internet is correct, but....
# sudo apachectl stop
# ...that the command will try to stop MAMP apache (not the built-in httpd service)
# The correct solution is to unload the correct apache
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
@peppeocchi
peppeocchi / ElasticBeanstalkHttps.php
Last active November 3, 2017 08:53
Laravel middleware for Elastic Beanstalk (HTTPS and Load balancer)
<?php namespace App\Http\Middleware;
use Closure;
/**
* Put this file in app/Http/Middleware
* Read more here https://github.com/peppeocchi/laravel-elb-middleware
*
*/
class ElasticBeanstalkHttps
@peppeocchi
peppeocchi / block_ip.txt
Created December 15, 2015 10:01
Block IP address
# in .htaccess
Order deny,allow
Deny from all
# if elastic beanstalk
SetEnvIF X-Forwarded-For "MY.IP.TO.BLOCK" blocked_ips
Order deny,allow
Deny from env=blocked_ips
# *nix iptables