Skip to content

Instantly share code, notes, and snippets.

@c0derabbit
c0derabbit / randomchoice.js
Created Jul 14, 2016
A JavaScript solution for random choice from an array.
View randomchoice.js
function randomChoice(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
@c0derabbit
c0derabbit / fontsizer.js
Last active Jul 22, 2018
JS snippet for increasing or decreasing font size in a HTML document using jQuery.
View fontsizer.js
function resize(increase_or_decrease) {
const direction = increase_or_decrease;
// First arg is the direction, elements to change follow
for (let i = 1; i < arguments.length; i++) {
let fontsize = parseInt($(arguments[i]).css('font-size'));
if (direction === 'increase') {
fontsize++;
if (fontsize > 20) fontsize = 20; // Prevent text from getting too big
} else if (direction === 'decrease') {
fontsize--;
@c0derabbit
c0derabbit / vat.py
Last active Sep 6, 2016
vat.py tells you what's the applicable VAT in the country of your choice. I wrote this one because at a previous workplace I had to check VAT in various countries quite often – but not often enough to memorize all.
View vat.py
# needed packages: beautifulsoup4, lxml
import requests as r
from bs4 import BeautifulSoup
from sys import argv
import re
# dictionaries for country codes and shortenings e.g. UK and UAE
country_dict = {'ch': 'Switzerland', 'gr': 'Greece', 'ee': 'Estonia', 'eg': 'Egypt',
'ea': 'United Arab Emirates', 'it': 'Italy', 'cz': 'Czech', 'cy': 'Cyprus', 'at': 'Austria',
'cs': 'Serbia', 'et': 'Ethiopia', 'ng': 'Nigeria', 'ie': 'Ireland', 'gh': 'Ghana',
You can’t perform that action at this time.