Skip to content

Instantly share code, notes, and snippets.

@gotofritz
gotofritz / js-tips-escaped-dollar.js
Created April 27, 2012 09:03
To have a $ in your replace strings in Javascript regular expressions, it needs to be escaped with another $ ($$) not a slash (\$)
"I <feeling> that".replace( /<(.+?)>/g, "\$$1" );
//won't work - will produce ""I $1 that""
"I <feeling> that".replace( /<(.+?)>/g, "$$$1" );
//works - "I $feeling that"
@gotofritz
gotofritz / find-without-svn.sh
Last active October 4, 2015 05:58
Various svn shorthands
cd DIR_FROM
find . \! \( -name . -or -name ".svn" -or -path "*/.svn/*" \) -print | cpio -padv PTH_TO
@gotofritz
gotofritz / resize padded.sh
Last active June 26, 2019 13:35
ImageMagick bits and pieces
# resize image, padded
@gotofritz
gotofritz / find-by-number-of-lines.sh
Last active November 13, 2016 17:10
various bash find command
#sort files by number of lines
find /path/to/folder -name '*.js' | xargs wc -l | sort
@gotofritz
gotofritz / random_color.js
Last active September 8, 2016 06:37
random color
//random color
//from: http://www.mrspeaker.net/2013/03/08/random-hex-colour/
//16777216 = 1 << 24
// ES5
function random_color(){
return '#'+ ( '00000' + ( Math.random() * 16777216 | 0 ).toString( 16 ) ).slice( -6 );
}
// ES6
@gotofritz
gotofritz / get_type.js
Created April 7, 2013 16:49
//gets type of a variable, all lower case
//gets type of a variable, all lower case
function get_type( what ){
return Object.prototype.toString.call( what ).slice( 8,-1 ).toLowerCase();
}
@gotofritz
gotofritz / pretty-print-json.sh
Created May 9, 2013 16:12
Pretty print Json on the command line
curl http://api.joind.in | python -mjson.tool
@gotofritz
gotofritz / prevent-select.css
Created October 9, 2013 11:44
for touch devices, disables selection
.preventSelect {
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
@gotofritz
gotofritz / _html5.html
Last active December 25, 2015 06:29
Minimal HTML documents
<!DOCTYPE html>
<html lang="en">
<head>
<!-- charset always before title to avoid UTF-7 exploits -->
<meta charset="utf-8">
<title>title</title>
<link rel="stylesheet" href="css.css">
</head>
<body>
@gotofritz
gotofritz / .Git bits and pieces
Last active August 22, 2017 18:33
Git bits and pieces
# Bulk Resolve Conflics
# Changing username after a commit
# Compare Versions
# Delete A Branch
# Empty Dirs
# Get Info
# Ignore A File That Was Already Pushed
# Log With Actual Changes
# Log With List Of Files
# Move Commits To Another Branch