Skip to content

Instantly share code, notes, and snippets.

@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() {
// ----- 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);
}
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) {
@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!";
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;
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]);
#!/bin/bash
# edit this, should be login details for sms.se and your phone number
loginnumber="0701234567"
password="abc123"
sendTo="0701234567"
# you shouldn't have to edit anything beyond this point
if [ $# != 1 ]; then
@vrutberg
vrutberg / QueryParser.java
Created August 21, 2009 14:31
Query Parser class for Lotus Notes/Domino written in Java
private class QueryParser {
public Hashtable parseQueryString(String qsd) {
// we will return this
Hashtable data = new Hashtable();
// check if it contains pairs of k/v
if(qsd.indexOf("&") > -1) {
String[] pairs = qsd.split("&");
for(int i = 0; i < pairs.length; i++) {
#!/bin/bash
wp_blogs=(
"/var/www/someblog/"
"/var/www/anotherblog/"
"/var/www/thirdblog/"
)
# get the latest wordpress files
echo "Downloading Wordpress and unpacking..."
@vrutberg
vrutberg / notesname.js
Created September 22, 2009 08:53
JavaScript implementation of the NotesName class
function NotesName(p) {
var name = p;
// regular expressions that we use to extract information
var Regexp = {
abbreviated: /(?:CN|OU|O|C)=/gi,
isName: /CN=.+(?:\/OU=.+)*\/O=.+(?:\/C=.+)?/i,
common: /CN=([\w\s]*)\//i,
given: /^(\w+)\s/,
surname: /\s(\w+)$/,