This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide.QtWebKit import * | |
class Everything(QObject): | |
@Slot(result=int) | |
def answer(self): | |
return 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var interval | |
, count = 0 | |
interval = setInterval(function(){ console.log(++count) }, 1000) | |
setTimeout(function(){ clearInterval(interval) }, 5000) | |
})(); | |
// should count up to 4/5 and stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def raiz_quadrada(numero): | |
"""Retorna a raiz quadrada do número passado como parâmetro. | |
""" | |
for chute in chute_uns_numeros(numero): | |
if chute_esta_bom(chute, numero): | |
return chute | |
def chute_esta_bom(chute, numero): | |
"""Retorna se o chute é uma aproximação boa o suficiente da raiz quadrada. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function contains(obj, value) { | |
return obj && obj.indexOf(value) != -1 | |
} | |
var checked = contains(sd_o, sd[i].id) // must be false or null to disable | |
var formElm = new Element('input', {'type': 'checkbox' | |
,'name': 'sideDish[]' | |
,'id': 'sideDish_' + sd[i].id | |
,'value': sd[i].id | |
,'checked': checked}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isNumeric(v) { | |
return !isNaN(+v) // implicit typecasting to Number, taking advantage of JavaScript's type coercion | |
} | |
function checkForm() { | |
var elms_to_test = ['coupon', 'ins', 'quantity', 'ref', 'dr'] | |
, el, i | |
for (i = elms_to_test.length; i--; ) { | |
// use getElementById to get a reference to the element with the given ID. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lowercased(fn): | |
fn.__name__ = fn.__name__.lower() | |
return fn | |
class Stuff(object): | |
@lowercased | |
def CamelCasedMethod(): | |
pass | |
print dir(Stuff) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------- | |
def indexPage(self, ctx): | |
scope = self | |
class IndexPage(Conditional): | |
def item(self): | |
return scope.page if scope.page.index else None | |
return IndexPage(ctx) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var fs = require('fs'); | |
var url = require('url'); | |
var settingsPath='settings2.json'; | |
var Server = function(path){ | |
this.readSettings(path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
from collections import defaultdict | |
class IdleProcess(object): | |
"""Process data when CPU is idle | |
""" | |
def __init__(self): | |
self.poll = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#!/usr/bin/python | |
from collections import defaultdict | |
class Eventful(object): | |
"""Any class that can respond to events. | |
""" | |
def __init__(self): | |
self.listeners = defaultdict(list) |