Skip to content

Instantly share code, notes, and snippets.

View ourway's full-sized avatar
🏆

Farshid Ashouri ourway

🏆
View GitHub Profile
@ourway
ourway / bi_contains
Created December 21, 2013 09:57
Efficient ways of searching sorted lists.
def bi_contains(lst, item):
"""The most efficient way of searching sorted lists.
@ref: http://goo.gl/ByYtjq
@param lst: The input list
@param item: The item i'm looking for
@return: True|False
"""
return (item <= lst[-1]) and (lst[bisect_left(lst, item)] == item)
@ourway
ourway / text2binary
Last active January 1, 2016 17:09
write arrays of numeric values to binary files
#!/usr/bin/env python
'''
@ref http://goo.gl/HgkAaG
@author Farsheed Ashouri
@usage: Give a folder of text files that contain 2d array of data:
5252,3434
4565,32123
...
import array
def convert_to_binary(path):
f = open(path, 'r')
o = open('%s.bin'%path, 'wa')
for line in f.readlines():
x,y = line.split(',')
data = array.array('i', [int(x),int(y)])
data.tofile(o)
@ourway
ourway / File-Search-Multi-process
Created December 31, 2013 13:40
Example of multi-process huge files searching
import multiprocessing, os, time
NUMBER_OF_PROCESSES = multiprocessing.cpu_count()
def FindText( host, file_name, text):
file_size = os.stat(file_name ).st_size
m1 = open(file_name, "r")
#work out file size to divide up to farm out line counting
chunk = (file_size / NUMBER_OF_PROCESSES ) + 1
@ourway
ourway / Dijsktra
Last active August 29, 2015 14:01 — forked from econchick/gist:4666413
Dijesktra algorithm
class Graph:
def __init__(self):
self.nodes = set()
self.edges = defaultdict(list)
self.distances = {}
def add_node(self, value):
self.nodes.add(value)
def add_edge(self, from_node, to_node, distance):

Gitlab Gmail configuration

In Gitlab 2.6 you must edit the following files in order to send messages through a Gmail account (also applicable to Google Apps accounts).

config/environments/production.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
from __future__ import unicode_literals
from bottle import Bottle, request, response
from mypkg import analyse_data
# http://www.reddit.com/r/learnpython/comments/1037g5/whats_the_best_lightweight_web_framework_for/
# http://bottlepy.org/docs/dev/tutorial.html
app = Bottle()
@ourway
ourway / websse.py
Last active August 29, 2015 14:07 — forked from werediver/websse.py
"""
Simple demonstration of how to implement Server-sent events (SSE) in Python
using Bottle micro web-framework.
SSE require asynchronous request handling, but it's tricky with WSGI. One way
to achieve that is to use gevent library as shown here.
Usage: just start the script and open http://localhost:8080/ in your browser.
Based on:
@ourway
ourway / aggs.sh
Last active August 29, 2015 14:07 — forked from jprante/aggs.sh
curl -XDELETE 'localhost:9200/test'
curl -XPUT 'localhost:9200/test' -d '
{
"mappings" : {
"_default_": {
"properties" : {
"name" : { "type" : "string" },
"age" : { "type" : "integer" },
@ourway
ourway / falcon_patch.py
Created October 19, 2014 10:34
Falcon append_header fix
class Response(falcon.response.Response):
def __init__(self):
super(Response, self).__init__()
self.extra_headers = list()
def append_header(self, name, value):
'''Fixes the problem of multiple Cookie headers.
@input
name, value