Skip to content

Instantly share code, notes, and snippets.

@eas604
eas604 / info.py
Created November 26, 2014 17:34
Modified version of the function from Dive Into Python.
def info(obj, spacing=10, collapse=True):
"""Print methods and doc strings.
:param obj: object to inspect
:type obj: module or class or list or dict or str or unicode
:param spacing: left column width
:type spacing: int
:param collapse: whether to collapse the text when printing
:type collapse: bool
"""
# Modified version of the function from Dive Into Python.
@eas604
eas604 / sha256_file.py
Last active December 22, 2020 17:45
sha256 file checksum function in python
def sha256_file(file_path, chunk_size=65336):
"""
Get the sha 256 checksum of a file.
:param file_path: path to file
:type file_path: unicode or str
:param chunk_size: number of bytes to read in each iteration. Must be > 0.
:type chunk_size: int
:return: sha 256 checksum of file
:rtype : str
"""
@eas604
eas604 / loadView.js
Created October 6, 2014 15:36
Simple async view loader in jQuery. Gets the target URL, then puts the output HTML in the target div.
function loadView(url, div) {
// Will get the result of the appropriate view url then display the data
// in the specified `div`, where `div` is a jQuery selector. Usage:
// var div = $("#my_target_div");
// var url = "~/Example/View";
// loadView(url, div);
$.get(url, function (data) { div.html(data); }, "html");
// Parameter dataType value "html" required on Firefox only, for some reason.
// See http://stackoverflow.com/questions/11441020/jquery-ajax-exception-only-in-firefox-node-cannot-be-inserted-at-the-specified
}