Short (72 chars or less) summary
More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).
Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
This file contains 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
<?xml version="1.0" encoding="UTF-8" ?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one or more | |
contributor license agreements. See the NOTICE file distributed with | |
this work for additional information regarding copyright ownership. | |
The ASF licenses this file to You under the Apache License, Version 2.0 | |
(the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 |
This file contains 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
PRINT_TOPIC = 1 | |
PAPER_ORIENTATION = 2 | |
APPLICATION_TOPIC = 3 | |
NO_HELP_TOPIC = -1 | |
class HelpHandler (object): | |
def __init__(self, successor=0, topic=NO_HELP_TOPIC): | |
self._successor = successor | |
self._topic = topic | |
def HasHelp(self): |
This file contains 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
''' | |
A python script which starts celery worker and auto reload it when any code change happens. | |
I did this because Celery worker's "--autoreload" option seems not working for a lot of people. | |
''' | |
import time | |
from watchdog.observers import Observer ##pip install watchdog | |
from watchdog.events import PatternMatchingEventHandler | |
import psutil ##pip install psutil | |
import os |
This file contains 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
# Note: it is a copy of great answer by "mgoldwasser" from Stackoverflow | |
# Check the original answer here: http://stackoverflow.com/a/26018934/1032439 | |
# Imagine that post1, post5, and post1000 are posts objects with ids 1, 5 and 1000 respectively | |
# The goal is to "upsert" these posts. | |
# we initialize a dict which maps id to the post object | |
my_new_posts = {1: post1, 5: post5, 1000: post1000} | |
for each in posts.query.filter(posts.id.in_(my_new_posts.keys())).all(): |
This file contains 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
""" | |
Upsert gist | |
Requires at least postgres 9.5 and sqlalchemy 1.1 | |
Initial state: | |
[] | |
Initial upsert: |
This file contains 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 <solr distribution> | |
$ bin/solr start | |
$ bin/solr create -c demo | |
$ curl http://localhost:8983/solr/demo/update?commitWithin=3000 -d '{delete:{query:"*:*"}}' | |
$ curl http://localhost:8983/solr/demo/update?commitWithin=3000 -d ' | |
[ | |
{id : book1, type_s:book, title_t : "The Way of Kings", author_s : "Brandon Sanderson", | |
cat_s:fantasy, pubyear_i:2010, publisher_s:Tor, bin_s: bar, | |
_childDocuments_ : [ |
This file contains 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
# Safe Queue Celery App Settings | |
from __future__ import absolute_import, unicode_literals | |
from celery import Celery | |
app = Celery('some_project', | |
broker='amqp://', | |
backend='amqp://', | |
include=['some_project.tasks']) |
This file contains 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
#!/usr/bin/env python | |
import requests | |
import hashlib | |
page_contents = requests.get('http://www.google.com') | |
response = page_contents.text | |
print hashlib.sha256(response.encode('utf-8')).hexdigest() |
This file contains 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
from sqlalchemy.dialects import postgresql | |
def bulk_upsert(session: Session, | |
items: Sequence[Mapping[str, Any]]): | |
session.execute( | |
postgresql.insert(MyModel.__table__) | |
.values(items) | |
.on_conflict_do_update( | |
index_elements=[MyModel.id], | |
set_={MyModel.my_field.name: 'new_value'}, |
OlderNewer