Skip to content

Instantly share code, notes, and snippets.

View fmelihh's full-sized avatar
🎃
Beast Mode

Furkan Melih Ercan fmelihh

🎃
Beast Mode
View GitHub Profile
@tuxdna
tuxdna / schema.xml
Last active February 10, 2023 11:03
Apache Solr sample schema configuration
<?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
@calderonroberto
calderonroberto / chainofresponsibility.py
Created July 8, 2015 06:28
Chain of responsibility in python (Design Patterns - Gamma, Helm, Johnson, Vlissides)
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):
@chenjianjx
chenjianjx / start-celery-for-dev.py
Created March 10, 2016 10:45
A python script which starts celery worker and auto reload it when any code change happens.
'''
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
@malexer
malexer / sqlalchemy_upsert.py
Last active January 26, 2024 14:09
Modelling UPSERT in SQLAlchemy (well actually it is not upsert but speed improvement is significant in comparison with simple session.merge)
# 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():
@bhtucker
bhtucker / upsert.py
Last active April 3, 2024 15:56
A demonstration of Postgres upserts in SQLAlchemy
"""
Upsert gist
Requires at least postgres 9.5 and sqlalchemy 1.1
Initial state:
[]
Initial upsert:
@sdavids13
sdavids13 / block_join_filter_example.txt
Last active March 22, 2023 10:57
Solr block join filtering example
$ 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_ : [
@IrSent
IrSent / celery.py
Created November 12, 2016 19:12
Celery Best Practices
# 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'])
@PSJoshi
PSJoshi / hash-webpage.py
Last active December 22, 2023 14:53
Hash a web page
#!/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()
@robertpainsi
robertpainsi / commit-message-guidelines.md
Last active July 17, 2024 12:55
Commit message guidelines

Commit Message Guidelines

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
@amorgun
amorgun / sample.py
Created November 10, 2017 10:51
SqlAlchemy postgres bulk upsert
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'},