Skip to content

Instantly share code, notes, and snippets.

View amix's full-sized avatar

Amir Salihefendic amix

View GitHub Profile
def add_job(self, job_type, job_id=None, on_duplicate='overwrite',
timestamp=None, distribute=None, **data):
"""
Add a new job to execute
:param job_type: string with the name of the job
:param job_id: job identifier, if not set, then a new random unique id
will be generated
:param on_duplicate: action on identifier duplicate, can be "overwrite"
or "discard"
@amix
amix / cluster_lines.py
Last active June 28, 2022 10:25
Groups (clusters) similar lines together from a text file using k-means clustering algorithm.
"""
Groups (clusters) similar lines together from a text file
using k-means clustering algorithm.
Also does some simple cleaning (such as removing white space and replacing numbers with (N)).
Example:
python cluster_lines.py --clusters 20 invalid_dates.txt
@amix
amix / highdef_canvas.coffee
Last active August 29, 2015 14:07
Configure a canvas element for high-def screens (retina)
# Configure a canvas element for high-def screens (retina)
highDefCanvas = (canvas, context) ->
pixel_ratio = window.devicePixelRatio
if pixel_ratio
width = canvas.width
height = canvas.height
canvas.width = width * pixel_ratio
canvas.height = height * pixel_ratio
canvas.style.width = "#{width}px"
canvas.style.height = "#{height}px"
@amix
amix / gist:c797168dd2ba56988886
Created July 21, 2014 23:08
Python gibberish
def main():
import aksfjaslkdfj
aksfjaslkdfj.blahblah
blah + blah2
blah3()
select {
case <- messageListener:
newData = c.GetMessages(offset)
listener <- newData
case <- time.After(ChannelTimeoutSec * time.Second):
listener <- ReturnDataEmpty
}
type Account struct {
balance float64
...
sync.Mutex
}
func (a *Account) Deposit(amount float64) {
a.Lock()
defer a.Unlock()
@amix
amix / gist:9507950
Last active August 29, 2015 13:57
Observer pattern in Go - with channel specific locking
import "sync"
type Channel struct {
...
messages []*Message
listeners []chan *Message
sync.Mutex
}
...
// JavaScript that solves http://regex.alf.nu/
// Run in Chrome or Firefox console
// Enjoy ;-)
// Some people, when confronted with a problem, think
// “I know, I'll use regular expressions.”
// Now they have two problems.
for(var lvl in levels) {
var fn = function(lvl) {
// JavaScript that solves http://regex.alf.nu/
// Run in Chrome or Firefox console
// Enjoy ;-)
// Some people, when confronted with a problem, think
// “I know, I'll use regular expressions.”
// Now they have two problems.
for(var lvl in levels) {
var fn = function(lvl) {
@pytest.yield_fixture
def v5_api_data():
with resources.project_ctx() as project, \
resources.item_ctx() as task1, \
resources.item_ctx() as task2, \
resources.item_ctx() as in_history:
with resources.note_ctx(item_id=task1.id) as note_task_1,\
resources.note_ctx(item_id=in_history.id) as note_task_3: