Skip to content

Instantly share code, notes, and snippets.

@fvicente
fvicente / get_langs.py
Created December 18, 2017 11:48
Dictionary of most used language by country based on https://stackoverflow.com/a/22202770/2962940
View get_langs.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as etree
import urllib
import pprint
def get_most_used_language_by_territory():
langxml = urllib.urlopen('http://unicode.org/repos/cldr/trunk/common/supplemental/supplementalData.xml')
langtree = etree.XML(langxml.read())
@fvicente
fvicente / world_selector.md
Last active December 18, 2017 20:34
Minecraft server world selector
View world_selector.md

Minecraft Server World Selector

This a very simple user interface that automatically edits the server.properties file, but it does not restarts the server.

Made in python 2.7 with pyside2. Using miniconda instead of venv, because pyside2 is not available through pip at this time.

Installation

  • Copy world_selector.py to your minecraft server directory.
@fvicente
fvicente / rgb_opacity.js
Last active August 5, 2017 00:07
RGB opacity calculator
View rgb_opacity.js
function colorHexToRGB(htmlColor) {
var COLOR_REGEX = /^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;
var arrRGB = htmlColor.match(COLOR_REGEX);
if (arrRGB === null) {
alert("Invalid color passed, the color should be in the html format. Example: #ff0033");
return null;
}
var red = parseInt(arrRGB[1], 16);
var green = parseInt(arrRGB[2], 16);
var blue = parseInt(arrRGB[3], 16);
@fvicente
fvicente / etree_overload.py
Created March 31, 2017 19:51
When you are creating an XML with ElementTree but you want to manipulate all the values of text nodes
View etree_overload.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as et
class OverloadedElement(et.Element):
def __setattr__(self, name, value):
if name == "text":
value = value.replace(u'ú', 'u')
value = value.replace(u'ô', 'o')
@fvicente
fvicente / flv.py
Created February 22, 2016 00:30
Extracting FLV meta tags with Python
View flv.py
from struct import unpack
from datetime import datetime
class FLVReader(dict):
"""
Reads metadata from FLV files
"""
# Tag types
@fvicente
fvicente / sony.py
Created September 13, 2015 03:16
Sony Entertainment Network spam stopper
View sony.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import urllib
import urllib2
import datetime
import sys
import time
@fvicente
fvicente / joystick.ino
Created September 13, 2015 01:56
Arcade Joystick with Teensy 3.0
View joystick.ino
/* Arcade Keyboard-Joystick */
#include <usb_keyboard.h>
#define NUM_BUTTONS 8
int keys[NUM_BUTTONS] = {KEY_RIGHT, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_ENTER, KEY_SPACE, KEY_LEFT_ALT, KEY_Z};
int mask = 0;
int i = 0;
void setup() {
@fvicente
fvicente / compress.iss
Last active June 8, 2018 19:21
Compress a directory in inno setup
View compress.iss
function MakeBackup(indir, outfile: String): Boolean;
var
res: Boolean;
fso: Variant;
winShell: Variant;
f: Variant;
inObj: Variant;
outObj: Variant;
begin
res := FALSE;
@fvicente
fvicente / denise.py
Last active September 13, 2015 01:59
Denise’s birthday problem solution (in Python)
View denise.py
# -*- coding: utf-8 -*-
from collections import defaultdict
# (dd, mmm, yyyy)
dates = [
(17, "Feb", 2001),
(13, "Mar", 2001),
(13, "Apr", 2001),
(15, "May", 2001),
(17, "Jun", 2001),