Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
#!/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() {
@flackend
flackend / parsley-promise-validator.js
Created March 28, 2017 17:21
I didn't know if Parsley could handle promise-based validators. While googling I found the annotated source for Parsley's remote.js (http://parsleyjs.org/doc/annotated-source/remote.html). All you have to do is return a promise-compatible object (see jQuery.when, https://api.jquery.com/jquery.when/).
Parsley.addValidator('vulnerabilityTitle', {
validateString: (value) => {
// Throws up a loading animation
loading.start();
return new Promise((resolve, reject) => {
VulnerabilityRepository.fetchAll().then((vulnerabilities) => {
let found = vulnerabilities.find((vulnerability) => {
return vulnerability.title == value;
});
loading.stop();
@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 / generate.js
Last active October 8, 2015 09:45
I wrote this to automate somewhat the task of moving some WordPress data to a new install. Didn't have Administrative permissions or server access so had to manually copy and paste. This method made it a lot faster. One script generates a payload and the other uses that payload to fill the form fields.
// GENERATE
function getScript(url, callback) {
var head = document.documentElement,
script = document.createElement('script'),
done = false;
script.src = url;
script.onload = script.onreadystatechange = function() {
body {
background: #f1f1f0 !important;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif !important;
font-weight: 300 !important;
}
/* h3 {font-weight:300 !important} */
.header-woof {display:none !important}