Skip to content

Instantly share code, notes, and snippets.

@BlakeGardner
BlakeGardner / Install HTTPie.md
Last active November 5, 2020 08:43
Install HTTPie Mac OS X

This is a quick guide on installing HTTPie for Mac OS X systems. This is also useful if you want the python package management utility pip. An installed copy of Homebrew is a prerequisite.

HTTPie

The easy way

brew install httpie
@BlakeGardner
BlakeGardner / install nano.sh
Last active July 8, 2024 03:56
Syntax highlighting in nano on Mac OS
# Last updated May, 2024 for Apple silicon Macs
# Install Homebrew if you don't already have it: https://brew.sh
# install nano from homebrew
brew install nano nanorc
# update your nanorc file
echo 'include "'"$(brew --cellar nano)"'/*/share/nano/*.nanorc"' >> ~/.nanorc
# close and re-open your terminal and you'll have syntax highlighting
@BlakeGardner
BlakeGardner / range.php
Created June 4, 2013 01:17
Simple implementation of range as a generator
<?php
$data = range(0, 1000000);
echo sprintf('%02.2f', (memory_get_usage() / 1048576))." MB of memory used\n";
// output: 137.92 MB of memory used
foreach ($data as $key => $val) {
//echo "key: ".$key." value: ".$val."\n";
@BlakeGardner
BlakeGardner / sample output
Last active December 18, 2015 14:49
Generate a change log automatically with git
#!/bin/bash
# Generate a changelog between the v1 and v2 tags
# See the "pretty formats" section of the git manual if you want to customize the output: https://www.kernel.org/pub/software/scm/git/docs/git-log.html
git log --no-merges --format="%an: %s" v1..v2
@BlakeGardner
BlakeGardner / benchmark.php
Last active February 13, 2018 17:47
Benchmark of all the hashing algorithms provided by PHP
<?php
foreach (hash_algos() as $algo) {
$start_time = microtime(TRUE);
for ($index = 0; $index <= 500000; $index++) {
$hash = hash($algo, $index);
}
@BlakeGardner
BlakeGardner / install gearman.sh
Last active April 25, 2017 07:03
How to compile and install the Gearman PECL extension on CentOS release 5.9
# Install IUS and EPEL yum repos
wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/5/x86_64/epel-release-5-4.noarch.rpm
wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/5/x86_64/ius-release-1.0-11.ius.centos5.noarch.rpm
rpm -i ius-release-1.0-11.ius.centos5.noarch.rpm epel-release-5-4.noarch.rpm
# make sure your system is up to date for good measure
yum update
# Install the required packages
yum install libgearman-devel php53u-devel gcc
@BlakeGardner
BlakeGardner / something.php
Created July 15, 2013 16:46
PHP SOMETHING challenge
Saw this interesting PHP Challenge.
Replace SOMETHING so that the output is Hello World.
if (SOMETHING) {
echo "Hello";
} else {
echo "World";
}
@BlakeGardner
BlakeGardner / install.sh
Last active December 21, 2015 01:08
Install gearman on CentOS with cpanel
wget http://dl.fedoraproject.org/pub/epel/6/SRPMS/gearmand-1.1.8-2.el6.src.rpm
yum install rpm-build libuuid-devel boost-devel boost-thread sqlite-devel tokyocabinet-devel libevent-devel libmemcached-devel memcached gperf postgresql-devel gperftools-devel
rpmbuild --rebuild ~/gearmand-1.1.8-2.el6.src.rpm
rpm -Uhv ~/rpmbuild/RPMS/x86_64/*.rpm
service gearmand start
@BlakeGardner
BlakeGardner / compact.js
Last active February 19, 2024 16:55
Compact all collections inside of a MongoDB database
// This script loops though the list of collection names in a MongoDB and runs the compact operation on them
// Simply paste this into the Mongo shell
use testDbName;
db.getCollectionNames().forEach(function (collectionName) {
print('Compacting: ' + collectionName);
db.runCommand({ compact: collectionName });
});
@BlakeGardner
BlakeGardner / Laravel 4.0.x.php
Last active August 29, 2015 13:56
Laravel log file changes
<?php
# /app/start/global.php
/*
This results in several dated log files
/app/storage/logs/log-apache2handler-2014-02-02.txt
/app/storage/logs/log-apache2handler-2014-02-03.txt