Skip to content

Instantly share code, notes, and snippets.

@jonbeebe
jonbeebe / list_splice.py
Last active September 6, 2021 07:14
Port of JavaScript Array.prototype.splice() to Python 3
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 September 24, 2013 09:22
general string left padding function in coffeescript
# 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 April 30, 2024 03:50
function to get the MouseEvent coordinates for an element that has CSS3 Transforms
/*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)
*/