Skip to content

Instantly share code, notes, and snippets.

@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();
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() {
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
#!/bin/bash
#
# _/_/_/ _/_/_/ _/_/_/_/
# _/ _/ _/
# _/ _/_/ _/ _/_/_/
# _/ _/ _/ _/
# _/_/_/ _/_/_/ _/
#
# Uses ffmpeg to generate
# animated gifs from mov
@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 / 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 / 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