Skip to content

Instantly share code, notes, and snippets.

@Narthe
Narthe / strip_accents.py
Created March 20, 2017 18:49
Strips accents from unicode string
# coding=utf-8
import unicodedata
def strip_accents(s):
return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn')
str1 = u"ÃÄÅÈÉÊËÌÍÎÏ"
str2 = u"ÙÚÛÜÝàáâãäåèéêëìíîïñòóôõöùúûüýÿ"
@Narthe
Narthe / split_string.cpp
Created September 13, 2016 19:20
split string by delimiter
#include <string>
#include <sstream>
#include <vector>
using namespace std;
void split(const string &s, char delim, vector<string> &elems) {
stringstream ss;
ss.str(s);
string item;
@Narthe
Narthe / extended_combobox.py
Created March 25, 2016 16:47
Dynamic combobox with sortFilterProxy
class ExtendedCombo( QtGui.QComboBox ):
def __init__( self, parent = None):
super( ExtendedCombo, self ).__init__( parent )
self.setFocusPolicy( QtCore.Qt.StrongFocus )
self.setEditable( True )
self.completer = QtGui.QCompleter( self )
# always show all completions
self.completer.setCompletionMode( QtGui.QCompleter.UnfilteredPopupCompletion )
@Narthe
Narthe / associates_path.bat
Created March 14, 2016 13:22
Associates a path with a drive letter
:: Creates a link
subst T: D:/path/to/dir
:: Removes link
subst T: /D
@Narthe
Narthe / get_folder architecture.py
Created March 9, 2016 13:40
Get the content (folders and files) from a location into a dict
def get_directory_structure(rootdir):
"""
Creates a nested dictionary that represents the folder structure of rootdir
"""
dir = {}
rootdir = rootdir.rstrip(os.sep)
start = rootdir.rfind(os.sep) + 1
for path, dirs, files in os.walk(rootdir):
folders = path[start:].split(os.sep)
subdir = dict.fromkeys(files)
@Narthe
Narthe / doxygen.sublime-snippet
Created February 9, 2016 09:01
Sublime snippet to create a doxygen description for a function with a single parameter and a return type
<snippet>
<content><![CDATA["""
Description
:param $1:
:type $1:
:rtype:
"""
]]></content>
class ButtonLineEdit(QtGui.QLineEdit):
buttonClicked = QtCore.pyqtSignal(bool)
def __init__(self, icon_file, parent=None):
super(ButtonLineEdit, self).__init__(parent)
self.button = QtGui.QToolButton(self)
self.button.setIcon(QtGui.QIcon(icon_file))
self.button.setStyleSheet('border: 0px; padding-right: 0px;')
self.button.setCursor(QtCore.Qt.ArrowCursor)
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
def drop_table():
c.execute('''DROP TABLE IF EXISTS courses''')
# Save (commit) the changes
conn.commit()
@Narthe
Narthe / Sublime snippet getter setter python
Last active March 5, 2021 00:55
Create getter and setter methods for python
<snippet>
<content><![CDATA[def get_$1(self):
return self._$1
def set_$1(self, $1):
self._$1 = $1;
]]></content>
<!-- Optional: Tab trigger to activate the snippet -->
<tabTrigger>getset</tabTrigger>
<!-- Optional: Scope the tab trigger will be active in -->
@Narthe
Narthe / dict_depth
Created January 30, 2015 09:19
dict depth
def dict_depth(d, depth=0):
if not isinstance(d, dict) or not d:
return depth
return max(dict_depth(v, depth+1) for k, v in d.iteritems())