Skip to content

Instantly share code, notes, and snippets.

View al3xandru's full-sized avatar

Alex Popescu al3xandru

View GitHub Profile
@al3xandru
al3xandru / gist:1032222
Created June 17, 2011 20:18
Getting started with VMware CloudFoundry, MongoDB and Node.js
var record_visit = function(req, res){
/* Connect to the DB and auth */
require('mongodb').connect(mongourl, function(err, conn){
conn.collection('ips', function(err, coll){
/* Simple object to insert: ip address and date */
object_to_insert = { 'ip': req.connection.remoteAddress, 'ts': new Date() };
/* Insert the object then print in response */
/* Note the _id has been created */
coll.insert( object_to_insert, {safe:true}, function(err){
@al3xandru
al3xandru / gist:1128606
Created August 5, 2011 21:51
nvALT Bookmarklet
javascript:(function({
var INSTAPAPER=true,w=window,d=document,pageSelectedTxt=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pageTitle=d.title,pageUri=w.location.href,tmplt="";
tmplt="From ["+pageTitle+"]("+pageUri+"):\n\n";
if(pageSelectedTxt!="") {
pageSelectedTxt=">%20"+pageSelectedTxt;
pageSelectedTxt=pageSelectedTxt.replace(/(\r\n|\n+|\r)/gm,"\n");
pageSelectedTxt=pageSelectedTxt.replace(/\n/g,"\n>%20\n>%20");
w.location.href="nvalt://make/?txt="+encodeURIComponent(tmplt+pageSelectedTxt)+"&title="+encodeURIComponent(pageTitle)
}
else {
@al3xandru
al3xandru / gist:1156476
Created August 19, 2011 09:48
Open iTerm in Current Folder
on run {input, parameters}
tell application "Finder"
set sel to selection
if (count sel) > 0 then
set myTarget to item 1 of sel
else if (count window) > 0 then
set myTarget to target of window 1
else
set myTarget to path to home folder
end if
@al3xandru
al3xandru / gist:1169583
Created August 24, 2011 23:31
OmniFocus Generalized Bookmarklet
javascript:(function(){
var enc=encodeURIComponent,
w=window,
frames=w.frames,
d=document,
tn=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),
pu=w.location.href,
isGMail=w.location.host.match(/mail\.google\.com/),
tt=pt=d.title,
subjSpans=d.getElementsByClassName("hP"),i,url;
@al3xandru
al3xandru / gist:1217265
Created September 14, 2011 17:58
BBEdit Maketags
-- Maketags
--
-- Builds ctags file for currently active project
--
-- Installation:
--
-- Copy script to either location:
-- ~/Library/Application Support/BBEdit/Scripts
-- ~/Dropbox/Application Support/BBEdit/Scripts
--
@al3xandru
al3xandru / gist:1230955
Created September 21, 2011 01:31
Choose a Waiting context in OmniFocus
-- accumulate all context names that contain the "wait" substring
repeat with anItem in (complete "wait" as context)
set waitingForContextNamesList to waitingForContextNamesList & {(name of anItem)}
end repeat
choose from list waitingForContextNamesList with prompt "Choose Waiting context…" OK button name "Set" cancel button name "Cancel"
set chosenWaitingForContext to result as string
set theContextID to id of item 1 of (complete chosenWaitingForContext as context)
-- this last line fails even if theContextID is correct
set theWaitingForContext to first context whose id is theContextID
@al3xandru
al3xandru / gist:1578357
Created January 8, 2012 13:27
Anyone could explain this mdfind (Spotlight) search results
-- first query looks for files containing both xhadoopx and xhbasex
'( kMDItemTextContent == "*xhadoopx*"wc && kMDItemTextContent == "*xhbasex*"wc )'
-- 2nd query searches for the same files but should filter out those containing xmapreducex
'( kMDItemTextContent == "*xhadoopx*"wc && kMDItemTextContent == "*xhbasex*"wc && kMDItemTextContent != "-xmapreducex"wc )'
-- but both return the same set of results
@al3xandru
al3xandru / gist:2063532
Created March 17, 2012 17:56
Git Submodules and Branches/Tags
According to the Git documentation when using submodules they are recorded at the exact commit they are, but not at symbolic references as master or branch or tag.
Here is a scenario:
1. check out a submodule into master project
2. switch to a specific branch or tag in the submodule
3. add submodule to the master project
4. commit master project
Questions:
javascript:(function(){var p=document.createElement("p");p.innerHTML="<strong>Loading&hellip;</strong>";p.id="loadingp";p.style.padding="20px";p.style.background="#fff";p.style.left="20px";p.style.top=0;p.style.position="fixed";p.style.zIndex="9999999";p.style.opacity=".85";document.body.appendChild(p);document.body.appendChild(document.createElement("script")).src="https://gist.github.com/al3xandru/6145492/raw/Bullseye.js?x="+(Math.random());})();