Skip to content

Instantly share code, notes, and snippets.

@flackend
flackend / README.md
Last active March 18, 2022 15:43
Home Raspberry Pi web server DNS

TL;DR: Using an old Raspberry Pi hosted at home in conjunction with CloudFlare and DuckDNS as $1/yr web hosting.

After cPanel hiked its prices, the hosting company I've been using went out of business. I looked for some shared hosting options. They ranged from $30 to $60 a year. That's much more than I want to pay (especially coming from a much better deal with my previous host). My solution is to host them at home on a Raspberry Pi.

I chose a Pi as my hardware versus a spare laptop, since a laptop would cost me at least $30 in electricity in a year. The Pi on the other hand will cost about $1 in electricity. The problem with hosting at home is my IP address will change from time to time. So I had to get a little creative.

I setup DuckDNS to track my IP address. http://example.duckdns.org points to my home IP address and there's a cron job on my Pi that updates my DuckDNS account every 5 minutes. So when my IP address changes, http://example.duckdns.org gets updated automatically.

I pointed my nam

@flackend
flackend / CDPATH.md
Last active February 22, 2022 21:57
Instructions for setting up CDPATH completions on Mac.

CDPATH

Overview

This will allow you to include additional directories to what cd will look at for completions. From the bash man page:

The search path for the cd command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the cd command.

Usage

@flackend
flackend / auth.php
Created February 5, 2020 02:14
Parts of this are pseudo code. The bit that's in focus is the idea of checking first if the form-supplied password, when md5 hashed, matches the user's password in the database.
<?php
try {
$user = get_user_from_database($emailFromLoginForm); // pseudo
if ($user->password === md5($plainTextPasswordFromLoginForm)) {
// We've identified that the password in the database is a md5 hash, so
// we'll salt and hash the plain-text password and save it
$saltedPassword = password_hash($plainTextPasswordFromLoginForm, PASSWORD_DEFAULT);
$user->password = $saltedPassword; // pseudo
@flackend
flackend / VirtualBox VDI Resizing.md
Last active November 8, 2019 05:46
Instructions for resizing a VirtualBox VDI

Resize VDI

Note: sudo cfdisk and df -h can come in handy to identify disks, etc. See there output below which will help identify how to adapt the commands.

df -h output:

Filesystem                   Size  Used Avail Use% Mounted on
udev                         980M     0  980M   0% /dev
tmpfs                        201M  3.4M  197M   2% /run
@flackend
flackend / colors.bash
Last active November 12, 2018 21:06
echo colors cheatsheet
#!/bin/sh -e
for attr in $(seq 0 1); do
for fg in $(seq 30 37); do
for bg in $(seq 40 47); do
printf "\033[$attr;${bg};${fg}m$attr;$fg;$bg\033[m "
done
echo
done
done
@flackend
flackend / Redirect After Session Expires.md
Last active October 20, 2018 12:44
Example solution to handling re-authentication after session expires for AJAX requests.

When a user's session expires and they're on a page that uses ajax requests, you need to set up something to gracefully handle reauthenticating. In this example, we prompt the user and redirect them to the login page.

demo

For Laravel, in your auth filter:

<?php
Route::filter('auth', function()
{
#!/bin/bash
#
# _/_/_/ _/_/_/ _/_/_/_/
# _/ _/ _/
# _/ _/_/ _/ _/_/_/
# _/ _/ _/ _/
# _/_/_/ _/_/_/ _/
#
# Uses ffmpeg to generate
# animated gifs from mov
THE BOY WHO LIVED
Mr. and Mrs. Dursley, of number four, Privet Drive,
were proud to say that they were perfectly normal,
thank you very much. They were the last people you’d
expect to be involved in anything strange or
mysterious, because they just didn’t hold with such
nonsense.
Mr. Dursley was the director of a firm called
describe("anyOtherFunctionName", function() {
it("should not use indexOf", function() {
var body = anyOtherFunctionName.toString();
expect(/indexOf/.test(body)).toBe(false);
expect(anyOtherFunctionName("a", "I am a hacker")).toBe(2);
});
it("should return a number", function() {
expect(typeof anyOtherFunctionName("a", "I am a hacker")).toBe("number");
});
it("should return the index of the first occurence of a string", function() {