Skip to content

Instantly share code, notes, and snippets.

View thigm85's full-sized avatar

Thiago G. Martins thigm85

View GitHub Profile
@thigm85
thigm85 / exception_with_variable_example.py
Created March 8, 2016 14:05
Example where an exception is raised with variables that can be accessed by the exception handler. Reference: https://docs.python.org/2/tutorial/errors.html#handling-exceptions
try:
raise Exception('spam', 'eggs')
except Exception as inst:
print type(inst) # the exception instance
print inst.args # arguments stored in .args
print inst # __str__ allows args to be printed directly
x, y = inst.args
print 'x =', x
print 'y =', y
@thigm85
thigm85 / reraise_exception_example.py
Created March 9, 2016 14:47
Incomplete example of how to reraise exception in python. Reference: https://docs.python.org/2/tutorial/errors.html#raising-exceptions
try:
raise NameError('HiThere')
except NameError:
print 'An exception flew by!'
raise
@thigm85
thigm85 / finally_clause_example.py
Created March 9, 2016 15:29
Example of using the optional finally clause in python exceptions. Reference: https://docs.python.org/2/tutorial/errors.html#defining-clean-up-actions
def divide(x, y):
try:
result = x / y
except ZeroDivisionError:
print "division by zero!"
else:
print "result is", result
finally:
print "executing finally clause"
object HelloWorld {
/* This is my first java program.
* This will print 'Hello World' as the output
*/
def main(args: Array[String]) {
println("Hello, world!") // prints Hello World
}
}
@thigm85
thigm85 / .bash_profile
Created March 13, 2017 11:00 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
import requests, json
data = json.loads(
requests.get("https://thigm85.github.io/data/mind/mind_demo_fields_parsed.json").text
)
data[0]
!pip install pyvespa
from vespa.package import ApplicationPackage
app_package = ApplicationPackage(name="news")
from vespa.package import Field
app_package.schema.add_fields(
Field(name="news_id", type="string", indexing=["summary", "attribute"], attribute=["fast-search"]),
Field(name="category", type="string", indexing=["summary", "attribute"]),
Field(name="subcategory", type="string", indexing=["summary", "attribute"]),
Field(name="title", type="string", indexing=["index", "summary"], index="enable-bm25"),
Field(name="abstract", type="string", indexing=["index", "summary"], index="enable-bm25"),
Field(name="url", type="string", indexing=["index", "summary"]),
Field(name="date", type="int", indexing=["summary", "attribute"]),