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
class StepsProcessor(object): | |
def __init__(self, steps, filename): | |
self.steps = steps | |
self.filename = filename | |
def process(self): | |
for i, step in self.enumerate_steps_to_process(): | |
try: | |
self.process_step(step) | |
except Exception: |
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
(function($) { | |
$.fn.previewTextareas = function() { | |
var $el = this; | |
var run = function(){ | |
var textareas = $('textarea', $el); | |
textareas.each(initializeTextarea); | |
}; |
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
ls -1 /data/torrents/ | while read NAME; do grep -qrF "$NAME" /var/transmission/config/torrents/ || echo $NAME; done |
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
# -*-coding: utf8 -*- | |
import unittest2 | |
from zope.interface import Interface | |
from zope.interface.declarations import implements, classImplements | |
class Storage(object): | |
CLASS_TEMPLATE = """ | |
class %(class_name)s(object): | |
def __init__(self, instance): |
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
import unittest2 | |
from django import forms | |
class DynamicForm(forms.Form): | |
""" | |
Allows to alter fields amount and requireness via spec, e.g.: | |
form = DynamicFormSubclass(spec={ | |
'last_name': False, # Drops field from initial form | |
'gender': {'required': True}, |
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
# -*- coding: utf8 -*- | |
import base64 | |
import os | |
import tempfile | |
from smtpd import DebuggingServer | |
from json import loads, dumps | |
class TestSmtpServer(DebuggingServer): |
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
# -*- coding: utf8 -*- | |
from datetime import timedelta | |
from fabric.context_managers import settings | |
from fabric.contrib.files import sed, exists | |
from fabric.operations import sudo, run, put | |
from fabric.state import env | |
useful_software_list = [ | |
'htop', |
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
type Point = { | |
$type: "PlainPoint"; | |
x: number; | |
y: number; | |
}; | |
const removeRedundantPoints = (points: Point[]) => { | |
const redundantIndexes: number[] = []; | |
for (let i = 0; i < points.length - 2; i++) { |
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
const uniq = <T>(arr: T[], fn: (el: T) => Object = (a) => a) => | |
arr.reduce<T[]>( | |
(acc, curr) => (acc.some((a) => fn(a) === fn(curr)) ? acc : [...acc, curr]), | |
[], | |
); | |
test("uniq", () => { | |
const deduped = uniq([{ a: 2 }, { a: -2 }], (el) => Math.abs(el.a)); | |
expect(deduped).toEqual([{ a: 2 }]); | |
}); |
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
const groupBy = <T extends { [k in K]: string }, K extends string>( | |
arr: T[], | |
attr: K, | |
) => { | |
return arr.reduce<{ [k in T[K]]?: T[] }>((result, item) => { | |
const k = item[attr]; | |
if (result[k] === undefined) { | |
result[k] = []; | |
} | |
(result[k] as T[]).push(item); |
OlderNewer