Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@adgedenkers
adgedenkers / vpn_connection.scpt
Created October 11, 2012 18:16
Toggle Connection to VPN on a Mac via AppleScript
tell application "System Events"
-- get current clipboard contents as a string
set CurrentClipboard to the clipboard as string
-- set the clipboad to your password
set the clipboard to "Y0urVPNPa$$w0rd"
-- start playing with the VPN
tell current location of network preferences
@nvahalik
nvahalik / custom google apps scripts for tech sales
Last active June 16, 2022 06:17
Some Google Apps Script functions for Spreadsheets which might be useful for those in Technical Sales or software development. They can be used to add up and manipulate hour ranges (e.g. SUMRANGE(["1-2",2,"2-5"]) would yield "5-9"). Those functions are SUMRANGE, SUMRANGEHIGH, SUMRANGELOW, RANGEMULT, and RANGEADD. There are also some functions wh…
/* Grab the values and make them globally available. */
var hoursPerDay = 8;
var hoursPerWeek = hoursPerDay * 5;
/**
* We calculate the number of hours in a given range.
*/
function SUMTIME(allData) {
var numHours = 0;
var numCells = allData.length;
@twksos
twksos / CiscoVPNConnection.scpt
Last active July 31, 2023 20:50
Cisco VPN connection auto connect AppleScript
-- Please set your vpn connection name and password here
set VPNName to "VPN name"
set VPNpassword to "VPN password"
tell application "System Events"
tell current location of network preferences
set VPNService to service VPNName
end tell
set isConnected to connected of current configuration of VPNService
@mttjohnson
mttjohnson / magento1_enterprise_index_diagnostics.sql
Last active November 9, 2017 19:53
Magento 1.x Enterprise Partial Indexing Diagnostics Toolset
-- When products are added/removed from a category this table stores all the relation data
select * from catalog_category_product where product_id = '24526';
-- The index that is used for presenting products in a category on the frontend
select * from catalog_category_product_index where product_id = '24526';
-- The change log table used for Magento EE partial index functionality
select * from catalog_category_product_index_cl where product_id = '24526' and version_id > (select version_id from enterprise_mview_metadata where changelog_name = 'catalog_category_product_index_cl');
# clear the entire cache
varnishadm "ban req.url ~ /"
# monitor varnish stats
varnishstat -n prod
# monitor varnish log with multiple patterns
varnishlog | grep 'eqURL\|Age:\|VCL_call\|TTL\|Expires:\|Cache-Control:'
# Use a query with varnishlog to watch requests from a specific IP
@mttjohnson
mttjohnson / mysql_size_info.sql
Last active April 29, 2021 08:30
MySQL data usage queries
/*
# Get size of a specific database into a bash variable for use in estimating mysqldump size for pv status bar
DATABASE_NAME="example_db_name"
DATABASE_SIZE=$(mysql --batch -sN -e "SELECT CONCAT(ROUND(sum( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 0), 'g') as size FROM information_schema.TABLES WHERE table_schema = '${DATABASE_NAME}' GROUP BY table_schema;")
echo "${DATABASE_SIZE}"
*/
/* find the largest tables on the server */
SELECT CONCAT(table_schema, '.', table_name) 'db.table',
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
@mttjohnson
mttjohnson / braintree_settlement.sh
Created November 29, 2016 23:22
Braintree manual transaction settlement
# Setup local directory with braintree example and libraries
git clone git@github.com:braintree/braintree_php_example.git
cd braintree_php_example
composer install
# Create and define configuration options
echo '
BT_ENVIRONMENT=sandbox
BT_MERCHANT_ID=xxxxxxxxxxxx
BT_PUBLIC_KEY=xxxxxxxxxxxx
@rchrd2
rchrd2 / test-php-basic-auth.php
Last active February 1, 2024 21:18 — forked from westonruter/test-php-basic-auth.php
PHP basic auth example
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
@mttjohnson
mttjohnson / mock-varnish-backend-request.sh
Last active April 5, 2019 15:43
Mock Varnish Backend Request
# Consider filtering the varnishlog output
# https://feryn.eu/blog/varnishlog-measure-varnish-cache-performance/
varnishlog -i "RespHeader,Req*" -X "RespHeader:(x|X)-" -I "timestamp:Resp" -x reqprotocol,reqacct -g request
# Capture the log output from varnishlog and look for BereqHeader
# -n name is how you can specify a specific named instance of varnish
# remove -n if you just want to access the default instance
varnishlog -n stage
@mttjohnson
mttjohnson / test_http_redirects.sh
Last active January 31, 2024 22:31
Testing HTTP Redirects
# The check_url recursive function
check_url() {
THIS_URL="${1}"
HTTP_RESP_CODE=$(curl -ksI "${THIS_URL}" | grep -i 'HTTP/' | cut -d' ' -f 2)
echo "${THIS_URL} -> ${HTTP_RESP_CODE}"
if [ "${HTTP_RESP_CODE}" == "301" ] || [ "${HTTP_RESP_CODE}" == "302" ]
then
HTTP_LOC=$(curl -ksI ${1} | grep -i 'Location: ' | cut -d'_' -f 2)
HTTP_REDIRECT=$(echo "${HTTP_LOC}" | tail -c +11 | tr -d '\r' | tr -d '\n')