Skip to content

Instantly share code, notes, and snippets.

function() {
function piratify(str) {
return str.replace(/pp/gi, "(pp)");
}
var tags = ['p','li','h1','h2','h3','h4','h5','h6','td','th'];
var texts = [];
for(var i = 0; i < tags.length; i++) {
texts = document.getElementsByTagName(tags[i]);
Array.prototype.each = function(callback) {
var i = this.length, j = 0;
while(i--) {
callback.call(this, this[j++]);
}
};
Array.prototype.contains = function(needle) {
var contains = false;
@vrutberg
vrutberg / stringValues.js
Created June 4, 2009 08:36
String manipulator for JavaScript
function formatString(str, values) {
for(var i in values) {
var pattern = /{/.source +i+ /}/.source;
str = str.replace(pattern, values[i]);
}
return str;
}
var str = "{fältnamn} är {typ}, var vänlig fyll i!";
var lines = document.getElementById('textArea').value.split("\n");
var prev = 0, str = "", blankLines = 0, total = "";
for(var n in lines) {
str = b[n];
if(str === "") {
blankLines++;
if(n == (lines.length-1) && blankLines !== 0) {
// ----- SÅHÄR GÖR JAG NU -----
while(doc != null)
{
// söker i hela databasen varje gång
Document searchDoc = someDatabase.search("MYFIELD=\""+ doc.getItemValueString("MYFIELD") +"\"").getFirstDocument();
// jobba med dokumentet...
doc = someView.getNextDocument(doc);
}
@vrutberg
vrutberg / .profile
Last active August 29, 2015 13:56
Handy .profile stuff
# finds files that by filename matches $1, does not reside in a target folder, and contains the string $2
findgrep() {
find . -name "*$1*" -and -type f -and -not -path "*/target/*" -and -not -path "*/.git/*" -print0 | xargs -0 fgrep -n --color=auto "$2"
}
# searches pom.xml files for $1
alias poms="findgrep 'pom.xml' $1"
# copies the output of the last command to the clipboard
copylast() {