Skip to content

Instantly share code, notes, and snippets.

@amitripshtos
amitripshtos / elasticsearch-py-async-bulk.py
Created October 28, 2018 14:13
Asyncio bulk helper methods for elasticsearch-py-async (python 3.6+) , use it like a regular helper, with AsyncElasticsearch
from __future__ import unicode_literals
import logging
from operator import methodcaller
import asyncio
from elasticsearch.exceptions import TransportError
from elasticsearch.helpers import BulkIndexError, expand_action, _chunk_actions
from elasticsearch.compat import map
@dzzh
dzzh / teamcity_github_pr_branch.py
Created March 7, 2017 15:07
Inject source and target branches from Github pull request into TeamCity CI
#!/usr/bin/env python
import os
import sys
import urllib2
import json
'''
This script queries Github for source and target branches of a pull request
and updates environment variables at TeamCity CI to make these variable
@jfriedlaender
jfriedlaender / init-postgresql-boxen
Last active October 1, 2015 16:53
Start Postgresql for Boxen
/opt/boxen/homebrew/bin/postgres -p 15432 -D /opt/boxen/data/postgresql -r /opt/boxen/log/postgresql/server.log
@Ulflander
Ulflander / Ultimate getter-setter IntellijIDEA live template.md
Last active August 8, 2018 22:05
The ultimate getter/setter IntellijIDEA live template

Suggested abbrevation: getset

Applicable in Java » Declaration

The live template:

/**
 * Set $DESC$.
@kunev
kunev / coroutines_example.py
Last active July 9, 2020 15:09
Coroutines example with python's asyncio module
import asyncio
@asyncio.coroutine
def open_file(name):
print("opening {}".format(name))
return open(name)
@asyncio.coroutine
def close_file(file):
print("closing {}".format(file.name))
@dbehnke
dbehnke / client.py
Created March 18, 2014 19:08
Python AsyncIO Client and Server Example using StreamReader and StreamWriter
"""
client.py - AsyncIO Server using StreamReader and StreamWriter
This will create 200 client connections to a server running server.py
It will handshake and run similar to this:
Server: HELLO
Client: WORLD
@kachayev
kachayev / topological.py
Last active December 30, 2022 10:21
Topological sort with Python (using DFS and gray/black colors)
# Simple:
# a --> b
# --> c --> d
# --> d
graph1 = {
"a": ["b", "c", "d"],
"b": [],
"c": ["d"],
"d": []
}
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active May 2, 2024 05:55
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

def rotate(matrix, n):
for layer in xrange(n/2):
first = layer
last = n - 1 - layer
for i in xrange(first, last):
offset = i - first
top = matrix[first][i]
# (0, 0) goes to (N-1, 0)
matrix[first][i] = matrix[last-offset][first]
# (0, N-1) goes to (0, 0)
@cyberdelia
cyberdelia / mixin.py
Created September 21, 2011 08:26
Django class based view mixins
# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import login_required
from django.utils.cache import patch_response_headers
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page, never_cache
from django.views.decorators.csrf import csrf_exempt
class NeverCacheMixin(object):
@method_decorator(never_cache)