Skip to content

Instantly share code, notes, and snippets.

View aderowbotham's full-sized avatar
👽

Adrian Rowbotham aderowbotham

👽
View GitHub Profile
@idleberg
idleberg / Install-Mcrypt.md
Last active May 31, 2023 17:13
Install Mcrypt on macOS

Setup php-mcrypt on macOS (and versions of Mac OS X)

These steps should have been mentioned in the prerequisites of the Laravel Installation Guide, since I'm surely not the only person trying to get Laravel running on macOS.

Install

Install Mcrypt using Homebrew and PECL (comes with PHP)

# PHP 7.3
@ecowden
ecowden / angular-partial-cache-busting
Created January 25, 2013 21:01
Cache busting for AngularJS partials is easy
/*
* Decide on your cache-busting strategy. In this example, we use the current timestamp, which will
* force a change every time the app is visited, but not every time the partial is loaded within a
* visit. Even better would be to use a hash of the file's contents to ensure that the file is always
* reloaded when the file changes and never reloaded when it isn't.
*/
var cacheBustSuffix = Date.now();
// Optionally, expose the cache busting value as a constant so other parts of your app can use it.
ngModule.constant("cacheBustSuffix", cacheBustSuffix);
@joshellington
joshellington / sftp-ubuntu.md
Created March 28, 2012 07:07
Basic tutorial for creating a SFTP-only user on Ubuntu 9.04 and greater

Adding SFTP-only user to Ubuntu Server

To add a SFTP-only user, you'll need to make sure your SSH config settings are correct, add a new user/group and set permissions for your new user. For step-by-step directions, see below. Omit sudo if you're logged in as root.

Directions

  1. Edit /etc/ssh/sshd_config and make sure to add the following at the end of the file:

     Match group filetransfer
    

ChrootDirectory %h

@philsturgeon
philsturgeon / gist:5465246
Last active May 23, 2022 12:29
API Golden Rules

Never Expose DB Results Directly

  1. If you rename a field, then your users are fucked. Convert with a hardcoded array structure.
  2. Most DB drivers [for PHP] will show integers as numeric strings and false as "0", so you want to typecast them.
  3. Unless you're using an ORM with "hidden" functionality, people will see passwords, salts and all sorts of fancy codes. If you add one and forget to put it in your $hidden array then OOPS!

Use the URI sparingly, and correctly

  1. Use the query string for paired params instead of /users/id/5/active/true. Your API does not need to be SEO optimised.
  2. ?format=xml is stupid, use an Accept: application/xml header. I added this to the CodeIgniter Rest Server once for lazy people, and now people think it's a thing. It's not.
@victorbstan
victorbstan / php_object_to_array.php
Created December 17, 2010 04:18
recursively cast a PHP object to array
<?php
/*
This function saved my life.
found on: http://www.sitepoint.com/forums//showthread.php?t=438748
by: crvandyke
It takes an object, and when all else if/else/recursive functions fail to convert the object into an associative array, this one goes for the kill. Who would'a thunk it?!
*/
$array = json_decode(json_encode($object), true);
@bdkjones
bdkjones / safesleep.txt
Created November 12, 2012 00:00
Disabling Safe Sleep After November, 2012
In early November, 2012, Apple issued a graphics update for all mid-2012 MacBooks. In a continued streak of stupidity, however, this update forces your Mac to use "Safe Sleep". This means that the entire contents of your RAM is written to your disk every time you put your Mac to sleep.
This is retarded on the scale of the Titanic's navigational plan for two reasons:
1) Your Mac likely has 8 or 16GB of RAM. This is a ton of wasted disk space; especially on MacBook Airs that ship with only 256GB SSDs to begin with.
2) SSDs wear out as you write to them. Each cell of a SSD can only be written to a certain number of times before it becomes read-only. If you put your computer to sleep many times a day, OS X is slowly but surely destroying your SSD with unneeded write cycles.
Worst of all, the graphics update makes it IMPOSSIBLE to turn off safe sleep using the standard approach you'll find on Google:
@prehensile
prehensile / dj-rnn.txt
Last active September 4, 2018 23:44
9012 DJ names generated by torch-rnn, trained on listings at residentadvisor.net
Aromino Lu
Farlos Gabate
Kukog Gracux
Cassunex De 90C
Alex Nede
Jeerra Bylentron
Eddeysive
Fair Figo
Andries Gamper
Ladewenteah
@adnan-i
adnan-i / angular-timeout.html
Last active March 16, 2017 11:55 — forked from orjan/angular-timeout.html
Workaround for $httpProvider.defaults As discussed here http://stackoverflow.com/a/15020611/1095616, it is not possible to set default timeout in $httpProvider. This gist offers a workaround.
<!doctype html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
</head>
<body>
<div ng-controller="TodoCtrl">
<button ng-click="beQuickOrBeDead()">Fetch with 100ms timeout</button>
<button ng-click="neverEndingStory()">Fetch with default timeout</button>
@axemonkey
axemonkey / fp
Created July 25, 2013 16:31
Everyone should have this in their .bash_profile
alias fp="echo -e ' _______...\n .-‘”..........``~.\n ,.-”..................“-.\n ,/........................”:\n ,?............................\ \n /..............................,}\n /...........................,:\`^\`.}\n /..........................,:”..../\n ?...__......................:\`...../\n /__.(...“~-,_.............,:\`...../\n /(_..”~,_....“~,_..........:\`...._/\n {._$;_...”=,_....“-,_...-~/~},.~”/.}\n ((...*~_....”=-._...“;,./\`./”...../\n \\\`~,...“~.,..........\`...}....../\n (..\`=-,,....\`............(...\_,-”\n /.\`~,...\`-................\\../^\\ \n \\\`~.*-,...................|/...\,__\n,,_ }.>-._\..................|........\`=~-,.. \n...\`=~-,_\\_...\`\\,.................\\.............. \n..........\`=~-,,.\\,................\\............. \n................\`:,,..............\`\\.......__.... \n...................\`=-,..........,%\`>--
@iainmullan
iainmullan / version_cmp.php
Created September 17, 2014 15:36
Compare version numbers of the format X.Y.Z (major.minor.patch)
<?php
/**
* Compare version numbers of the format X.Y.Z where X,Y,Z are non-negative integers
* Values with less than three parts will be padded out with zeros, eg. "1.1" becomes "1.1.0", "1" becomes "1.0.0"
*
* @return 1 if $a is greater (a later version) than $b, 0 if $a is equal to $b, -1 if $a is less (an earlier version) than $b
*
*/
function version_cmp($a, $b) {