This file contains hidden or 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
| <?php | |
| class Generator { | |
| private $start = '1'; | |
| function __construct($start = null) { | |
| if ($start != null) { | |
| $this->start = (string) $start; | |
| } | |
| } |
This file contains hidden or 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
| class A: | |
| def __init__(self): | |
| print(u'конструктор класса A') | |
| class B(A): | |
| def __init__(self): | |
| print(u'конструктор класса B') | |
| A.__init__(self) |
This file contains hidden or 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
| exports.serialize = function (obj) { | |
| var str = []; | |
| for (var p in obj) { | |
| str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); | |
| } | |
| return str.join("&"); | |
| }; |
This file contains hidden or 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
| from os import path | |
| print path.dirname(path.realpath(__file__)) |
This file contains hidden or 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 chardet | |
| def encode(string): | |
| if not string: | |
| return '' | |
| if not isinstance(string, unicode): | |
| encoding = chardet.detect(string) | |
| if not encoding['encoding']: |
This file contains hidden or 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 | |
| # -*- coding: utf-8 -*- | |
| import os | |
| import sys | |
| import time | |
| import signal | |
| def termination_handler(signum, frame): | |
| global running |
This file contains hidden or 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
| use test | |
| db.zips.aggregate({ | |
| $group : { | |
| _id : { state: '$state', city: '$city'} | |
| , totalPop : { $sum: '$pop' } | |
| } | |
| },{ | |
| $match : { | |
| totalPop: {$gte : 25000}, |
This file contains hidden or 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
| use test | |
| db.zips.aggregate([ | |
| { $project: { | |
| first_char: {$substr : ["$city",0,1]}, | |
| pop: 1 | |
| } | |
| }, { $match: { | |
| first_char: /[0-9]/ | |
| } |
This file contains hidden or 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
| use blog | |
| db.posts.aggregate([ | |
| { $unwind: "$comments" } | |
| , { $group: { | |
| _id: "$comments.author" | |
| , total: {$sum: 1} | |
| } | |
| } | |
| , { $sort: { total: -1 } } |
This file contains hidden or 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
| use test | |
| db.grades.aggregate([ | |
| { $unwind: "$scores" } | |
| , { $group: { | |
| _id: { | |
| type: "$scores.type" | |
| , score: "$scores.score" | |
| , class_id: "$class_id" | |
| } |