Skip to content

Instantly share code, notes, and snippets.

def validate_query(query, possible_columns):
q = validate_query_structure(query)
sort_field = q.get('_sortField')
filters = q.get('_filters', [])
columns = [field_name for field_name in filters]
if sort_field is not None:
columns.append(sort_field)
def _make_context_immutable(context):
"""Best effort attempt at turning a properly formatted context
(either a string, dict, or array of strings and dicts) into an
immutable data structure.
If we get an array, make it immutable by creating a tuple; if we get
a dict, copy it into a MappingProxyType. Otherwise, return as-is.
"""
def make_immutable(val):
if isinstance(val, Mapping):
const element = document.getElementById("test");
const cssObj = window.getComputedStyle(element, null);
let text = "";
for (x in cssObj) {
cssObjProp = cssObj.item(x)
text += cssObjProp + " = " + cssObj.getPropertyValue(cssObjProp) + "<br>";
}
>> y1 = Yeah('yes')
>> y1.name
__getattribute__ name
'yes'
>> y1.foo
__getattribute__ foo
__getattr__ foo
>> y1.foo
__getattribute__ foo
'orphan'
class Yeah(object):
def __init__(self, name):
self.name = name
# Gets called when an attribute is accessed
def __getattribute__(self, item):
print '__getattribute__ ', item
# Calling the super class to avoid recursion
return super(Yeah, self).__getattribute__(item)
# Gets called when the item is not found via __getattribute__
def __getattr__(self, item):
""" Симуляция "Жизни".
Игра жизни Конвея — это классическая автоматизация, созданная в 1970 году Джоном
Конвей. https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
Упражнение для практики
1. Можете ли вы поменять изобрженния точек?
2. Можете ли вы ускорить симуляцию?
3. Как бы вы изменили начальное состояние?
# coding=utf-8
from countryinfo import CountryInfo
country = CountryInfo('Bangladesh')
country.geo_json()
# returns object of GeoJSON data
{
'features': [
package main
import (
"log"
"os"
"strconv"
"github.com/hibiken/asynq"
"github.com/joho/godotenv"
"github.com/vert3xo/mcscan/tasks"
function fixedFromCharCode (codePt) {
2
if (codePt > 0xFFFF) {
3
codePt -= 0x10000;
4
return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
5
} else {
6
# Python code showing practical
# use of format_map() function
def chk_msg(n):
# input stored in variable a.
a = {'name':"George", 'mesg':n}
# use of format_map() function
print('{name} has {mesg} new messages'.format_map(a))