Skip to content

Instantly share code, notes, and snippets.

View DamianMullins's full-sized avatar
💭
👽

Damian Mullins DamianMullins

💭
👽
View GitHub Profile
@DamianMullins
DamianMullins / strip_js.py
Created August 13, 2012 19:47
Filter out script tags from a string
@register.filter
@stringfilter
def stripjs(value):
stripped = re.sub(r'<script(?:\s[^>]*)?(>(?:.(?!/script>))*</script>|/>)', \
'', force_unicode(value), flags=re.S)
return mark_safe(stripped)
@DamianMullins
DamianMullins / clean_url.py
Created August 13, 2012 19:50
Check that submitted URL is unique and allowed
def clean_url(self):
INVALID_URLS = ('about', 'admin', 'register')
url = self.cleaned_data['url']
try:
post = Post.objects.get(url=url)
except Post.DoesNotExist:
pass
else:
raise forms.ValidationError(u'%s already exists' % post )
@DamianMullins
DamianMullins / gist:3425388
Created August 22, 2012 13:05
GIT Shell Aliases
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&'
alias gx='gitx --all'
alias got='git '
@DamianMullins
DamianMullins / gist:3452075
Last active March 23, 2023 11:44
Increment or decrement textbox value using arrow up & down keyboard keys
function change(element, increment) {
var $el = $(element),
elValue = parseInt($el.val(), 10),
incAmount = increment || 1,
newValue = elValue + incAmount;
if ((newValue) > -1) {
$el.val(newValue);
}
}
@DamianMullins
DamianMullins / gist:6230365
Created August 14, 2013 11:51
Windows CMD: puts the date and time on the line along with the folder, and starts the prompt on the next line
PROMPT=$C$D$S$T$H$H$H$H$H$H$F$S$P$_$G$S
Execute a function by specifying its name as a string.
-----
A [Pen](http://codepen.io/anon/pen/AgCDt) by [Anonasaurus Rex](http://codepen.io/anon) on [CodePen](http://codepen.io/).
[License](http://codepen.io/anon/pen/AgCDt/license).
@DamianMullins
DamianMullins / Uninstall-NpmPackages.ps1
Last active August 29, 2015 14:24
Uninstall npm packages by scanning packages.json file.
Function Uninstall-NpmPackages {
Param (
# Optional path to package.json
[String]$pathToPackage = $(Resolve-Path "package.json")
)
# Read the json content
$json = (Get-Content $pathToPackage) -join "`n" | ConvertFrom-Json
# Loop over each package in devDependencies
@DamianMullins
DamianMullins / Uninstall-NpmPackagesInDirectory.ps1
Last active August 29, 2015 14:24
Uninstall npm packages by scanning directories inside node_modules
Function Uninstall-NpmPackagesInDirectory {
Param (
# Optional path to node_modules directory
[String]$pathToNodeModules = (Get-Item -Path ".\node_modules").FullName
)
# Loop over each folder in the directory
ForEach ($dep in Get-ChildItem -Path $pathToNodeModules | ? { $_.FullName -notmatch ".bin" }) {
# Uninstall the package
iex "npm uninstall $dep"
@DamianMullins
DamianMullins / getElementsByDataAttribute.js
Last active October 30, 2015 13:48
Returns an array of elements with a matching data attribute name.
/**
* Returns an array of elements with a matching data attribute name.
* @example
* let value = getElementsByDataAttribute('component-name');
*/
export default function getElementsByDataAttribute(name) {
var elements = document.querySelectorAll(`[data-${name}]`);
return Array.prototype.slice.call(elements);
};
@DamianMullins
DamianMullins / getDataAttributeValue-es2015.js
Last active January 13, 2016 14:51
Return data attribute value from a given element. Falls back to `getAttribute()` in older browsers.
/**
* Return data attribute value from a given element. Falls back to `getAttribute()` in older browsers.
* @example
* let value = getDataAttributeValue(element, 'component-name');
* @example
* let value = getDataAttributeValue(element, 'componentName');
*/
export default function getDataAttributeValue(element, dataName, defaultDataValue = '') {
const datasetSupported = element.dataset !== undefined;