Skip to content

Instantly share code, notes, and snippets.

@jonbeebe
jonbeebe / list_splice.py
Last active Sep 6, 2021
Port of JavaScript Array.prototype.splice() to Python 3
View list_splice.py
def list_splice(target, start, delete_count=None, *items):
"""Remove existing elements and/or add new elements to a list.
target the target list (will be changed)
start index of starting position
delete_count number of items to remove (default: len(target) - start)
*items items to insert at start index
Returns a new list of removed items (or an empty list)
"""
@avitevet
avitevet / pad.coffee
Created Sep 24, 2013
general string left padding function in coffeescript
View pad.coffee
# val = the value to pad
# length = the length of the padded string
# padChar = the character to use for padding. Defaults to '0'
pad = (val, length, padChar = '0') ->
val += ''
numPads = length - val.length
if (numPads > 0) then new Array(numPads + 1).join(padChar) + val else val
@Yaffle
Yaffle / convertPointFromPageToNode.js
Last active Jul 2, 2021
function to get the MouseEvent coordinates for an element that has CSS3 Transforms
View convertPointFromPageToNode.js
/*jslint plusplus: true, vars: true, indent: 2 */
/*
convertPointFromPageToNode(element, event.pageX, event.pageY) -> {x, y}
returns coordinate in element's local coordinate system (works properly with css transforms without perspective projection)
convertPointFromNodeToPage(element, offsetX, offsetY) -> {x, y}
returns coordinate in window's coordinate system (works properly with css transforms without perspective projection)
*/