Skip to content

Instantly share code, notes, and snippets.

function counter() {
var n = 0;
return function() {
n++;
return n;
}
}
c = counter();
c(); // ouputs 1
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);
/*
* 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() {
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
from celery.worker.control import Panel
@Panel.register
def my_custom_command(*args):
print('Yay, my custom command just ran!')
from celery import app
app.control.broadcast('my_custom_command')
// Angular 1.2+
function sendReq(config, reqData) {
/* SNIP */
if (isUndefined(cachedResp)) {
var xsrfValue = urlIsSameOrigin(config.url)
? $$cookieReader()[config.xsrfCookieName || defaults.xsrfCookieName]
: undefined;
const obj = {foo: 1, bar: 2, biz: 3, baz: 4}
const x = subset(obj, ['foo', 'baz'])
// x == {foo: 1, baz: 4}
function createFoo(foo) {
// 3rd party lib
return newFooId
}
function deleteFoo(fooId) {
// 3rd party lib
}
function doTheThing() {
# -*- coding: UTF-8 -*-
DAYS_OF_THE_WEEK = {
"en_US": {"Sunday": 0, "Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4, "Friday": 5, "Saturday": 6},
"es_ES": {"Domingo": 0, "Lunes": 1, "Martes": 2, "Miercoles": 3, "Jueves": 4, "Viernes": 5, "Sabado": 6},
"ja_JP": {"日曜日": 0, "月曜日": 1, "火曜日": 2, "水曜日": 3, "木曜日": 4, "金曜日": 5, "土曜日": 6},
}
REVERSE_DAYS_OF_THE_WEEK = dict((locale, dict(map(reversed, days.items())))
for locale, days in DAYS_OF_THE_WEEK.items())