Skip to content

Instantly share code, notes, and snippets.

@smitsgit
smitsgit / sqlalchemy_resources.txt
Last active July 14, 2020 04:15
SQL Alchemy Resources
https://www.youtube.com/watch?v=399c-ycBvo4 - Brandon Rhodes
https://www.youtube.com/watch?v=51RpDZKShiw - Jason Mayer
Slides: https://www.slideshare.net/jamdatadude/introduction-to-sqlalchemy-orm
Miguel Grinberg
One to Many Relationship example : https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iv-database
Many to May Relationship example : https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-viii-followers
Four tips : https://blog.miguelgrinberg.com/post/video-four-sqlalchemy-tips
SQl-alchemy docs:
@smitsgit
smitsgit / sample.txt
Last active June 14, 2020 08:43
Python library bootstrap
pip install cookiecutter / brew install cookiecutter
Talk by Mark Smith
https://www.youtube.com/watch?v=QgZ7qv4Cd0Y
$ cookiecutter gh:ionelmc/cookiecutter-pylibrary
$ cookiecutter https://github.com/Nekroze/cookiecutter-pypackage.git [ Worked Fine ]
Talk by Dave forgac
https://www.youtube.com/watch?v=qOH-h-EKKac&feature=emb_err_woyt
# Collection of useful python decorators
# Taken from https://eli.thegreenplace.net/2012/08/22/easy-tracing-of-nested-function-calls-in-python
# Easy tracing of nested function calls in Python
import sys
from functools import wraps
class TraceCalls(object):
""" Use as a decorator on functions that should be traced. Several
functions can be decorated - they will all be indented according
" vim-bootstrap
"*****************************************************************************
"" Vim-PLug core
"*****************************************************************************
let vimplug_exists=expand('~/.vim/autoload/plug.vim')
let g:vim_bootstrap_langs = "c"
let g:vim_bootstrap_editor = "vim" " nvim or vim
data class Customer(val name: String, val fidelityScore: Int)
data class LineItem(val productName: String, val qtyInKg: Int, val pricePerKg: Double) {
fun total(): Double {
return qtyInKg * pricePerKg
}
}
class Order(val customer: Customer, val cart: List<LineItem>, val promo: ((Order) -> Double)? = null) {
data class Customer(val name: String, val fidelityScore: Int)
data class LineItem(val productName: String, val qtyInKg: Int, val pricePerKg: Double) {
fun total(): Double {
return qtyInKg * pricePerKg
}
}
class Order(val customer: Customer, val cart: List<LineItem>, val promo: Promotion? = null) {
fun generator() = generate<Int, String> {
var c = 1
while (true) {
val op = yield(c)
when (op) {
"inc" -> c += 1
"mult" -> c *= 2
}
}
}
package generator
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
/*
ES6-style generator that can send values between coroutine and outer code in both ways.
Note that in ES6-generators the first invocation of `next()` goes not accept a parameter, but
just starts a coroutine until a subsequent `yield`, so to adopt it for the type-safe interface
we must declare `next` to be always invoked with a parameter and make our coroutine receive the first
package generator
import java.io.File
fun canHandle(func: () -> Boolean): Boolean {
return func()
}
fun firstHandler(successor: Generator<String, String>? = null) = generate<String, String>{
package generator
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun kotlincoro() = generate<String, String>{
println("[ coroutine ]: started")
println("[ coroutine ]: suspended at first yield and sent data to main")
val coroData = yield("Hello") // yield() causes coroutine to produce value "Hello" for consumer
// and kotlincoro function gets suspended till consumer invokes