Skip to content

Instantly share code, notes, and snippets.

View HorridModz's full-sized avatar

HorridModz HorridModz

View GitHub Profile
@brainyfarm
brainyfarm / truncate_a_string.py
Created August 8, 2016 08:03
FreeCodeCamp: Truncate a String (Python)
"""
Truncate a string (first argument) if it is longer than the given maximum string length (second argument).
Return the truncated string with a ... ending.
Note that inserting the three dots to the end will add to the string length.
However, if the given maximum string length num is less than or equal to 3,
then the addition of the three dots does not add to the string length in determining the truncated string.
"""
def truncate(string, num):
@pylover
pylover / inspections.txt
Last active May 11, 2025 18:25 — forked from ar45/inspections.txt
PyCharm inspections
# Extracted using: $ unzip -p lib/pycharm.jar com/jetbrains/python/PyBundle.properties | grep -B1 INSP.NAME | grep '^#' | sed 's|Inspection||g' | sed -e 's|#\s\{,1\}|# noinspection |'
# noinspection PyPep8
# noinspection PyPep8Naming
# noinspection PyTypeChecker
# noinspection PyAbstractClass
# noinspection PyArgumentEqualDefault
# noinspection PyArgumentList
# noinspection PyAssignmentToLoopOrWithParameter
# noinspection PyAttributeOutsideInit
@indraniel
indraniel / python-call-method-from-string.py
Created August 31, 2015 20:31
Python: How to dynamically call a method/function given a string of its name
# Based on reading : http://stackoverflow.com/questions/7936572/python-call-a-function-from-string-name
# http://stackoverflow.com/questions/3061/calling-a-function-of-a-module-from-a-string-with-the-functions-name-in-python
class Foo(object):
def dynamic_call(self, attribute_name):
method_name = 'calculate_' + attribute_name # e.g. given attribute name "baz" call method "calculate_baz"
func = getattr(self, method_name) # find method that located within the class
func() # execute the method
@octocat
octocat / .gitignore
Created February 27, 2014 19:38
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #