Skip to content

Instantly share code, notes, and snippets.

This is a sprinkler system with zones and waterings.
A zone is an area that can be watered. It has an ID.
A watering is a scheduled event that consists of an ordered list of zones and how long to water them (durations). Duplicate zones are allowed.
So the API returns data like this:
```
GET /watering/123456
/*
* Your challenge: Find the bug in this code.
*
* The symptom: When I click "Remove" on "Bob", "Fred" disappears. Why?
*
* Hint: It's not a syntax error, and there are no console warnings.
*/
class MyComponent extends React.Component {
constructor() {
function getCurrentUser(callback) {
$http.get("/api/users/self/").then(function(user) {
callback(user);
});
});
function getCurrentUser() {
var deferred = $q.defer();
$http.get("/api/users/self/").then(function(user) {
deferred.resolve(user);
function counter() {
var n = 0;
return function() {
n++;
return n;
}
}
c = counter();
c(); // ouputs 1
void my_function() {
char *data = malloc(1024);
return; // oops! memory leak
}
scale 562949953421312
bad at 1125899906842624 0x4000000000000 0b100000000000000000000000000000000000000000000000000
scale 281474976710656
bad at 562949953421312 0x2000000000000 0b10000000000000000000000000000000000000000000000000
scale 140737488355328
bad at 281474976710656 0x1000000000000 0b1000000000000000000000000000000000000000000000000
scale 70368744177664
import itertools
for a, b, c, d, e, f in itertools.product(range(1, 10), range(1, 10), range(1, 10), range(1, 10), range(1, 10), range(1, 10)):
if (a + b + c == 18 and
d + e + f == 18 and
a + d == b + e and
b + e == c + f and
int(str(e) + str(f)) in [16, 25, 36, 49, 64, 81] and
len(set([a, b, c, d, e, f])) == 6):
print a, b, c, d, e, f
print "You can see this"
with suppress_stdout():
print "You cannot see this"
print "And you can see this again"
from contextlib import contextmanager
import sys, os
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
>>> do_something.func_defaults = ([42],)
>>> do_something()
[42, 'some item']
>>>