Skip to content

Instantly share code, notes, and snippets.

######### using python mongoengine
min_age = Customer.objects(zip_code = 687218).order_by("age").first().age
max_age = Customer.objects(zip_code = 687218).order_by("-age").first().age
######### using mongo client commands
#MIN
db.customers.find({"zip_code":683749}).sort( { age: 1 } ).limit(-1)
@olgakogan
olgakogan / gmail_api.md
Last active December 14, 2022 11:53
Manually get OAuth credentials to access your gmail account via API

Basic setup

  1. Access the developer console https://console.developers.google.com
  2. Create a new project
  3. In APIs and Oauth section:
    a. In APIs section - enable gmail api
    b. In Credentials section -
    1. Click Create new client ID
    2. Fill email and project name
    3. Save
@olgakogan
olgakogan / Dictionary_get.swift
Created October 31, 2014 13:49
Swift - get from dictionary, with default value
extension Dictionary {
func get(key: Key, defaultValue: Value) -> Value {
/**
Returns the value for the given key (if exists), otherwise returns the default value.
*/
if let value = self[key] {
return value
} else {
@olgakogan
olgakogan / sql_alchemy_samples.py
Last active February 7, 2023 22:49
SQL Alchemy Samples
########## CASE IN UPDATE STATEMENT ############
from sqlalchemy import case
# single value modification (the 'else' is not mandatory)
session.query(User).update({User.status : case([(User.status == "pending", "approved")], else_=User.status)}, False)
# multiple values modification
session.query(User).update({User.status : case([(User.status == "pending", "approved"),
(User.status == "waiting", "deprecated_status")])}, False)