Skip to content

Instantly share code, notes, and snippets.

@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',
@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 / 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 / unique_id.js
Last active Sep 30, 2017
Creates a unique ID in JavaScript
View unique_id.js
const id = Date.now() + Math.random().toString(16).substr(2);
@c0derabbit
c0derabbit / string_calculator.js
Created Jul 14, 2016
Calculator in num1(operation(num2())); format, just for fun.
View string_calculator.js
// Link to kata: http://www.codewars.com/kata/calculating-with-functions/javascript
// How it works:
// seven(times(five())); // returns 35
// four(plus(nine())); // returns 13
// eight(minus(three())); // returns 5
// six(dividedBy(two())); // returns 3
function zero() {
if (arguments.length == 0) return 0;
@c0derabbit
c0derabbit / downloader.py
Created Sep 9, 2016
Downloads the file on the given url and saves it to the current directory.
View downloader.py
#!/usr/bin/env python3
import os
import os.path
import requests
def dl(url):
'''
Downloads the file on the given url and saves it to the current directory.
'''
r = requests.get(url)
@c0derabbit
c0derabbit / myio.py
Last active Sep 9, 2016
Python module for basic I/O operations
View myio.py
def read(filename):
'''
Opens a file and prints its lines in the console.
Takes 1 arg (string): filename
'''
with open(filename) as f:
for line in f:
print(line.rstrip())
def add(filename, text):
@c0derabbit
c0derabbit / random_hexcolor.py
Created Sep 12, 2016
Generates a random hexadecimal color (e.g. #ff0000)
View random_hexcolor.py
def random_hexcolor():
color = '#'
while len(color) < 7:
hex = '{0:x}'.format(random.randrange(256))
if len(hex) < 2:
hex = '0' + hex
color += hex
return color
@c0derabbit
c0derabbit / fix_npm_command_not_found.md
Last active Oct 17, 2016
Fix: npm packages not installing correctly
View fix_npm_command_not_found.md

You are reading the right document if you install packages with npm, e.g.:
npm i -g unicorns and after typing unicorns -v, you get unicorns: command not found.

Solution 1:

sudo chown -R $USER /usr/local should solve the problem.
Make sure your prefix is /usr/local, (you can check it with npm config get prefix).
If not, you can set it with npm config set prefix /usr/local

Solution 2:

@c0derabbit
c0derabbit / img-resize.py
Created Sep 30, 2017
Python Image Resizer
View img-resize.py
import os
import sys
from PIL import Image
def is_image(filename):
return filename[-3:].lower() in ["png", "jpg", "jpeg", "bmp"]
def resize_images_in(folder):
for filename in os.listdir(folder):
if not is_image(filename):
You can’t perform that action at this time.