Skip to content

Instantly share code, notes, and snippets.

@lele85
lele85 / wordpress_comment.py
Created June 1, 2009 13:35
wordpress_comment.py
import xmlrpclib
class comment:
def __init__(self, content, author, author_url, author_email, comment_parent = 0):
self.comment_parent = comment_parent
self.content = content
self.author = author
self.author_url = author_url
self.author_email = author_email
@lele85
lele85 / di_hello.py
Created January 31, 2012 20:36
Dependency Injection Hello World in python
from datetime import *
class ConsoleMessageWriter:
def __init__(self):
pass
def write(self, message):
print message
class LoggedMessageWriter:
@lele85
lele85 / di_hello.cs
Created January 31, 2012 20:39
Dependency Injection Hello World in C#
using System;
using System.Configuration;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
namespace HelloDI
{
public class MainClass
{
@lele85
lele85 / mainloop.html
Created February 4, 2012 17:14
Canvas 2D main loop test
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function(){
function Ball(x, y, radius, speedX, speedY){
this.LEFT_LIMIT = 0;
this.RIGHT_LIMIT = 800;
this.TOP_LIMIT = 0;
@lele85
lele85 / snow.html
Created February 6, 2012 19:17
Canvas 2D test cosine
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onload = function(){
/*
* Get mouse event coordinate converted to canvas coordinate
* c: The canvas object
* e: A mouse event
@lele85
lele85 / pomodoro.js
Created March 10, 2012 19:38
Pomodoro in nodeJS
function createPomodoro(params) {
var validOrDefaultDuration = function(duration){
var DEFAULT_POMODORO_DURATION = 1000;
return (duration !== undefined) ? duration : DEFAULT_POMODORO_DURATION;
}
var _started = false;
var _finished = false;
var _duration = validOrDefaultDuration(params.duration);
@lele85
lele85 / pomodoroTest.js
Created March 10, 2012 19:40
Pomodoro Test in nodeJS con WRU
wru.test([
{
name: "Can create a pomodoro",
test: function () {
//Arrange
var pomodoroFactory = require('../pomodoro');
//Act
var p = pomodoroFactory.create({});
//Assert
wru.assert(p !== undefined);
@lele85
lele85 / setTimeoutTest.js
Created March 13, 2012 19:35
setTimeout
var count = 1;
var ping = function(cb){
setTimeout(function()
{
console.log("P....... " + count * 200 + "ms");
count++;
cb(ping);
},200);
}
var getAuthString = function(username, password){
return 'Basic ' +Titanium.Utils.base64encode(username+':'+password);
};
var xhr = Titanium.Network.createHTTPClient();
xhr.open("GET", "http://requestb.in/1a0zngb1");
xhr.cache = false;
xhr.enableKeepAlive = false;
xhr.timeout = 30000;
xhr.setRequestHeader("Content-type", "application/json");
var os_type = Titanium.Platform.getOsname() == 'android'?'android':'ios';
var xhr = Titanium.Network.createHTTPClient();
var getNotCached = function(url){
var timestamp = new Date().getTime();
if (url.indexOf('?') == -1) {
return url + '?nocache=' + timestamp ;
}
return url + '&nocache=' + timestamp ;