Skip to content

Instantly share code, notes, and snippets.

View plasticbrain's full-sized avatar

Mike Everhart plasticbrain

View GitHub Profile
@plasticbrain
plasticbrain / newton.go
Last active March 7, 2016 06:28
Go: Newton's method of approximating square roots
package main
import (
"fmt"
"math"
)
const DELTA = 0.00000001
@plasticbrain
plasticbrain / .htaccess
Created February 14, 2016 00:39
Block Spammy Referrals with .htaccess
## Block spammy referrals
RewriteCond %{HTTP_REFERER} годом\.рф [NC]
RewriteCond %{HTTP_REFERER} traffic2cash\.xyz [NC]
RewriteCond %{HTTP_REFERER} free-traffic\.xyz [NC]
RewriteCond %{HTTP_REFERER} share-buttons\.xyz [NC]
RewriteCond %{HTTP_REFERER} maps\.ilovevitaly\.com [NC]
RewriteRule .* - [F]
@plasticbrain
plasticbrain / gulpfile.js
Last active February 13, 2024 14:31
gulp.js task to deploy code to remote servers
/*******************************************************************************
* Description:
*
* Gulp file to push changes to remote servers (eg: staging/production)
*
* Usage:
*
* gulp deploy --target
*
* Examples:
@plasticbrain
plasticbrain / _responsive.scss
Created January 11, 2016 17:27
CSS Media Queries w/ Bootstrap Responsive Breakpoints
/*
$screen-xs: 480px !default; // Extra small screen / phone
$screen-sm: 768px !default; // Small screen / tablet
$screen-md: 992px !default; // Medium screen / desktop
$screen-lg: 1200px !default; // Large screen / wide desktop
*/
@plasticbrain
plasticbrain / next_occurrence.php
Last active November 13, 2015 22:48
PHP - Calculate the next occurrence of a given date
<?php
// Usage
$occurrences = next_occurrence('Friday', 13);
foreach($occurrences as $day) {
echo $day->format('D M j, Y') . PHP_EOL;
}
@plasticbrain
plasticbrain / metrics-curl.rb
Created October 12, 2015 16:01
Sensu - Plugin for checking a page load time via curl
#! /usr/bin/env ruby
#
# metrics-curl
#
# DESCRIPTION:
# Simple wrapper around curl for getting timing stats from the various phases
# of connecting to an HTTP/HTTPS server.
#
# OUTPUT:
# metric data
@plasticbrain
plasticbrain / check_mysql.json
Created September 25, 2015 17:39
Sensu check for MySQL
{
"checks": {
"mysql": {
"command": "/usr/local/bin/check-mysql-alive.rb --host :::mysql.host::: --user :::mysql.user::: --password :::mysql.password::: --database :::mysql.database:::",
"interval": 60,
"occurrences": 1,
"refresh": 900,
"subscribers": [
"mysql"
],
@plasticbrain
plasticbrain / check_http.json
Last active September 25, 2015 17:38
Sensu check for http
{
"checks": {
"http": {
"command": "/usr/local/bin/check-http.rb --url ':::http.url:::' --query ':::http.query:::' --timeout :::http.timeout|5:::",
"interval": 60,
"occurrences": 1,
"subscribers": [
"http"
],
"handlers": [ "default", "mailer", "slack"]
@plasticbrain
plasticbrain / check_cpu.json
Last active September 25, 2015 19:46
Sensu check for cpu
{
"checks": {
"cpu": {
"command": "/usr/local/bin/check-cpu.rb -w :::system.cpu_warning|85::: -c :::system.cpu_critical|90:::",
"interval": 15,
"occurences": 4,
"subscribers": [
"cpu"
]
}
@plasticbrain
plasticbrain / check_disk.json
Created September 24, 2015 18:36
Sensu check for disks
{
"checks": {
"disk": {
"command": "/usr/local/bin/check-disk-usage.rb -w 85 -c 90",
"interval": 300,
"subscribers": [
"linux"
]
}
}