-
If you have an array
$a = array( 0, 1, 2, 3, 4 );
, how do you extract the value 3 from the array? -
If you have an array
$a = array( "zero"=>0, "one"=>1, "two"=>2, "three"=>3, "four"=>4 );
, how do you extract the value 3 from the array? -
If you have the following array, how do you extract the value 3 from the array?
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/env python | |
# -*- coding: utf-8 -*- | |
# Example of Singleton design pattern | |
# Copyright (C) 2011 Radek Pazdera | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. |
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
"""SQLAlchemy Metadata and Session object""" | |
from sqlalchemy import MetaData | |
from sqlalchemy.orm import scoped_session, sessionmaker | |
from sqlalchemy.orm.session import Session as SessionBase | |
from sqlalchemy.interfaces import ConnectionProxy | |
from datetime import datetime | |
import time | |
__all__ = ['Session', 'metadata', 'BaseModel'] |
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 -*- | |
from tornado import ioloop, web, gen, httpclient | |
from sockjs.tornado import SockJSConnection, SockJSRouter | |
class IndexHandler(web.RequestHandler): | |
"""Regular HTTP handler to serve the ping page""" | |
def get(self): |
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
from __future__ import annotations | |
from typing import Any, Dict, Iterable, Mapping, MutableMapping, MutableSequence, Union | |
class AttrDict: | |
""" | |
A class with both dictionary and attribute style access to it's data member. | |
It can be used in `RestrictedPython <http://restrictedpython.readthedocs.io/>`_ |
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 get_count(q): | |
count_q = q.statement.with_only_columns([func.count()]).order_by(None) | |
count = q.session.execute(count_q).scalar() | |
return count | |
q = session.query(TestModel).filter(...).order_by(...) | |
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ... | |
print q.count() |
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
# Assuming an Ubuntu Docker image | |
$ docker run -it <image> /bin/bash |
When hosting our web applications, we often have one public IP
address (i.e., an IP address visible to the outside world)
using which we want to host multiple web apps. For example, one
may wants to host three different web apps respectively for
example1.com
, example2.com
, and example1.com/images
on
the same machine using a single IP address.
How can we do that? Well, the good news is Internet browsers
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 asyncio | |
@asyncio.coroutine | |
def open_file(name): | |
print("opening {}".format(name)) | |
return open(name) | |
@asyncio.coroutine | |
def close_file(file): | |
print("closing {}".format(file.name)) |
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
# ATTENTION PLEASE! | |
# NOTE BY @riwazp7 | |
# Note for future visitors of this gist: Mac OS has Apache Benchmark by default ab --help | |
curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | |
tar -xzf libtool-2.4.2.tar.gz | |
cd libtool-2.4.2 | |
./configure && make && sudo make install | |
# brew install 'https://raw.github.com/simonair/homebrew-dupes/e5177ef4fc82ae5246842e5a544124722c9e975b/ab.rb' |
OlderNewer