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
SELECT * | |
FROM products | |
NATURAL JOIN items | |
WHERE items.keywords @@ to_tsquery('apple') | |
AND items.retailer_location_id = 123 |
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
CREATE FUNCTION dot_product(embedding1 real[], embedding2 real[]) | |
RETURNS real | |
LANGUAGE plpgsql | |
IMMUTABLE | |
AS $$ | |
DECLARE | |
dot_product real; | |
BEGIN | |
SELECT SUM(multiplied.values) INTO dot_product | |
FROM (SELECT UNNEST(embedding1) * UNNEST(embedding2) AS values) AS multiplied; |
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
Products (1TB) - 100x wider than Items | |
╔══════╦════════════╦═════╦═══════╦═════════════════╗ | |
║ id ║ name ║ upc ║ emoji ║ 100KB more data ║ | |
╠══════╬════════════╬═════╬═══════╬═════════════════╣ | |
║ 1 ║ fuji apple ║ 123 ║ 🍏 ║ ... ║ | |
║ 2 ║ gala apple ║ 456 ║ 🍎 ║ ... ║ | |
║ 3 ║ fuji water ║ 789 ║ 🌊 ║ ... ║ | |
╠══════╩════════════╩═════╩═══════╩═════════════════╣ | |
║ ... 10M more rows ... ║ | |
╚═══════════════════════════════════════════════════╝ |
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
require 'benchmark' | |
$CYCLE = 10_000_000 | |
class HashString | |
def initialize | |
@attrs = {} | |
end | |
def attr=(value) |
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
# install virtualenv | |
pip install virtualenv | |
# create a virtualenv | |
virtualenv ~/venvs/a_cool_project | |
# install your thing in its own virtualenv | |
~/venvs/a_cool_project/bin/pip install a_cool_project | |
# make the virtualenv installed executable available system wide |
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
# install lore | |
$ pip install --upgrade lore | |
# setup dependency managment | |
$ cd my_app | |
$ lore init . --bare --python-version=3.6.6 # 2 or 3, whatever | |
# Ship it! | |
$ git commit -a -m 'deep freeze dependencies' | |
$ git push |
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
$ cd my_app | |
$ lore python # launch python in my_app's virtualenv | |
$ lore pip # my_app's pip | |
$ lore console # my_app's ipython (installed in virtualenv) | |
$ lore notebook # my_app's jupyter notebook | |
$ lore lab # my_app's jupyter lab | |
$ lore exec # execute anything in my_app's virtualenv/bin/ | |
$ lore env # see what else is in there | |
$ lore test # you do have unit tests, don't you? |
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
$ git init . | |
$ git add . | |
$ git add -f models/my_app.models.product_popularity/Keras/1 # or your preferred fitting number to deploy | |
$ git commit -m "My first lore app!" |
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
$ pip3 install lore | |
$ git clone https://github.com/montanalow/my_app.git | |
$ cd my_app | |
$ lore install # caching all dependencies locally takes a few minutes the first time | |
$ lore server & | |
$ curl "http://localhost:5000/product_popularity.Keras/predict.json?product_name=Banana&department=produce" |
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
$ heroku login | |
$ heroku create | |
$ heroku config:set LORE_PROJECT=my_app | |
$ heroku config:set LORE_ENV=production | |
$ git push heroku master | |
$ heroku open | |
$ curl “`heroku info -s | grep web_url | cut -d= -f2`product_popularity.Keras/predict.json?product_name=Banana&department=produce” |