Skip to content

Instantly share code, notes, and snippets.

View preslavrachev's full-sized avatar

Preslav Rachev preslavrachev

View GitHub Profile
// Create a Signal without specific Value Classes
var signal:Signal = new Signal();
// Add listeners
signal.add(myListener);
signal.add(myOtherListener);
// Dispatch signal
signal.dispatch();
@preslavrachev
preslavrachev / showbbox.js
Created September 7, 2011 19:51
Getting the Bounding Box of an SVG Element
var bb = null;
function drawRect(e)
{
var elm = e.target;
// fixes for 'use' elements
if(!elm.getBBox)
{
if(elm.correspondingUseElement)
@preslavrachev
preslavrachev / gist:1205644
Created September 9, 2011 07:00
Defining class methods in Ruby
class MyClass
# All of these are equivalent
def self.myMethod
true
end
def MyClass.myMethod
true
end
@preslavrachev
preslavrachev / gist:1205653
Created September 9, 2011 07:06
Class methods in Ruby
class SelfStudy
attr_accessor :name
def self
@name
end
def self.name
@name
end
@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());
}
}
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: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');
bestOf ("Java","Python") == "Groovy" ? "YES" : "NO"
//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) {
@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) {
...
});