Skip to content

Instantly share code, notes, and snippets.

View preslavrachev's full-sized avatar

Preslav Rachev preslavrachev

View GitHub Profile
#include <iostream>
using namespace std;
void theWrapperFunction(int (*fnc) ()) {
cout << fnc();
}
int theCallBackFunction() {
return 12345;
}
var p = function() {
console.log("Executing the callback function");
}
var c = function(callBack) {
console.log("Executing the wrapper function");
}
c(p);
@preslavrachev
preslavrachev / test.js
Created July 19, 2012 10:01
Matching multiple hashtags in javascript
var c = "it ws a #nice and #sunny day in Berlin";
c.match(/\B#\w*[a-zA-Z]\w*/g); //should return #nice and #sunny
/* we are using the assumption that every entity is constructed recursively as every child component is given an id of +1
so it could be that my id is #5, but if I have 7 child components, the ID of my next neighbor (the next entity constructed by my parent, which is on the same tree level ) will be #13, because I will be constructed recursively to the lowest level first */
public static void sendMessage(String methodName, Object args)
{
int id = 5;
int parentId = 0;
@preslavrachev
preslavrachev / gist:1433175
Created December 5, 2011 10:40
Backbone.js: binding an event listener to respond when the url has been changed
//binding an event listener to respond when the url has been changed
router.bind("route:help", function(page) {
...
});
//via //http://www.google.com/codesearch#VcEPaUaJ3Zo/trunk/spring/org.springframework.context.support/src/main/java//org/springframework/mail/javamail/JavaMailSenderImpl.java&q=JavaMailSenderImpl&type=cs
public void send(MimeMessagePreparator mimeMessagePreparator) throws MailException {
send(new MimeMessagePreparator[] { mimeMessagePreparator });
}
public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException {
try {
List<MimeMessage> mimeMessages = new ArrayList<MimeMessage>(mimeMessagePreparators.length);
for (MimeMessagePreparator preparator : mimeMessagePreparators) {
bestOf ("Java","Python") == "Groovy" ? "YES" : "NO"
@preslavrachev
preslavrachev / gist:1234790
Created September 22, 2011 13:39
A Javascript stacktrace in any browser
// thanks to http://eriwen.com/javascript/js-stack-trace/
function printStackTrace() {
var callstack = [];
var isCallstackPopulated = false;
try {
i.dont.exist+=0; //doesn't exist- that's the point
} catch(e) {
if (e.stack) { //Firefox
var lines = e.stack.split('\n');
Proj.View.CustomView2 = Proj.View.CustomView.extend({
initialize: function(opts) {
//this is the equivalent of super()
Proj.View.CustomView.prototype.initialize.call(this,opts);
//....
},
render: function(opts) {
//this is the equivalent of super()
@preslavrachev
preslavrachev / gist:1217650
Created September 14, 2011 20:14
Iterate through HashMap
public static void printMap(Map mp) {
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
}
}