Skip to content

Instantly share code, notes, and snippets.

import os
import constants
from langchain.vectorstores import FAISS
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.document_loaders import PyPDFLoader
from langchain.indexes import VectorstoreIndexCreator
os.environ['OPENAI_API_KEY'] = constants.APIKEY
@Gpzim98
Gpzim98 / Python
Last active April 26, 2018 10:34
1 - ############ built-in zip function for i, j in zip(list1, list2)
2 - ############ built-in enumerate function for i,j in enumerate(lista) i = indice j = element
3 - ############ accessing a global variable a = 10 def foo(): global a a = 10
4 - ########### range performance
Python 2.7
@Gpzim98
Gpzim98 / DRF
Last active November 17, 2017 15:35
Django Rest Framework views best practices
# 1 - Ideal DRF View
from rest_framework import status
from rest_framework.decorators import detail_route
from rest_framework.response import Response
import logging
def do_log(e):
logger = logging.getLogger('django')
time = datetime.datetime.now()
# T1 - Exceptions
In general keep exceptions in views, not in models.
Put exceptions in models just when very necessary like to make process atomic or multiples tasks,
even in this case think if is not better split the method in multiple methos and treat exception in each method
# T2 - Always try to name the relationships
# T3 - Concentrate business logic into models methods and Managers
# T4 - Always help_text
In module 'UIKit' imported from /Users/gregorypacheco/Library/Developer/Xcode/DerivedData/Cataki-dxdbfptxbcfahtclbubecydrrlpk/Build/Intermediates.noindex/ArchiveIntermediates/Cataki/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/include/Cordova/CDVPlugin.h:21:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:459
:63: note: property 'statusBarHidden' is declared deprecated here
@property(readwrite, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController prefersStatusBarHidden]") __TVOS_PROHIBITED;
^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:459:63: note: 'setStatusBarHidden:' has been explicitly marked deprecated here
/Users/gregorypach
@Gpzim98
Gpzim98 / Linux
Last active October 23, 2017 12:49
# 1 - Find file terminal
find ~/ -type f -name "generate_interval.py"
# 2 - Checking HD size
df -H
# 3 - Tailing a log in realtime
tailor -f file.log
# 4 - If else param script bash
@Gpzim98
Gpzim98 / IAM
Created October 23, 2017 10:23
Roles
- Or you might want to allow a mobile app to use AWS resources, but not want to embed AWS keys within the
app (where they can be difficult to rotate and where users can potentially extract them).
Sometimes you want to give AWS access to users who already have identities defined outside of AWS, such as in your corporate
directory. Or, you might want to grant access to your account to third parties so that they can perform an audit on your resources.
@Gpzim98
Gpzim98 / EC2
Created October 12, 2017 15:41
Fixed Performance Instances (e.g. M3, C3, and R3)
Burstable Performance Instances
- T2
- Accrue CPU Credits when they are idle
- It stores them in its CPU Credit balance for up to 24 hours.
- If and when your t2.small needs to burst to more than 20% of a core, it draws from its
CPU Credit balance to handle this surge seamlessly
Cluster
# 1 - Promisses
p.then(onFulfilled[, onRejected]);
p.then(function(value) {
// fulfillment
}, function(reason) {
// rejection
});
# 2 - Find an object in a array
- obj, created = AppSettings.objects.get_or_create(name='DEFAULT_LANG')
- Uso do dir(obj)
- Dont use exception as a flow control
- every exception should do log
- Database tips from brazilian guy article