This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def strip_accents(text): | |
""" | |
Strips the accents, replace the dd, and lower case | |
""" | |
text = text.replace("đ", "d").replace("Đ", "d") | |
text = unicodedata.normalize("NFD", text) | |
text = text.encode("ascii", "ignore") | |
text = text.decode("utf-8") | |
text = text.lower() | |
return text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Detect platform in bash | |
# https://stackoverflow.com/a/3466183/459745 | |
case $(uname -s) in | |
Linux*) platform=Linux;; | |
Darwin*) platform=Mac;; | |
CYGWIN*) platform=Cygwin;; | |
MINGW*) platform=MinGw;; | |
*) platform=Unknown;; | |
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function, unicode_literals | |
import os | |
import re | |
import subprocess | |
""" | |
Sample listdlls output: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import logging | |
class JSONFormatter: | |
""" | |
A simple formatter class which takes a record and return the fields | |
in JSON format | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class App { | |
public void start() { | |
} | |
public static void main(String[] args) { | |
App app = new App(); | |
app.start(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T m_var; | |
public T getVar() { return this.m_var; } | |
public Class setVar(T newValue) { this.m_var = newValue; return this; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.southeastwind.test; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.junit.Test; | |
import static org.hamcrest.Matchers.is; | |
import static org.junit.Assert.assertThat; | |
import static net.southeastwind.test.SameMapAs.sameMapAs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Given a text file, provide a quick and easy way to return a range of | |
lines | |
""" | |
from itertools import islice | |
def select_lines(iterable, start_line, last_line): | |
# text lines usually 1-based, whereas islice is 0-base ==> -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
In unittest, assertItemsEqual() does not work for lists of objects, | |
even if these objects implement the __eq__ method for comparison. | |
This module provide assertUnorderedListsEqual() which does the job. | |
""" | |
import unittest | |
def list_diff(a, b): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
In unittest, when we need to compare two objects via assertEqual(), we | |
have two choices: implement the class' __eq__() or write a comparison | |
function and register it via addTypeEqualityFunc(). Each of these | |
approaches has its pros and cons. | |
The __eq__ Method | |
================= | |
Pros |
NewerOlder