Skip to content

Instantly share code, notes, and snippets.

@eirenik0
eirenik0 / scrapper.py
Last active August 29, 2015 14:20 — forked from madjar/scrapper.py
import asyncio
import aiohttp
import bs4
import tqdm
@asyncio.coroutine
def get(*args, **kwargs):
response = yield from aiohttp.request('GET', *args, **kwargs)
return (yield from response.read_and_close(decode=True))
jQuery.extend({
annotation: function (node, re, nodeName, className, settings) {
if (node.nodeType === 3) {
var match = node.data.match(re);
if (match) {
var annotation = document.createElement(nodeName || 'span');
annotation.className = className || 'annotation';
var wordNode = node.splitText(match.index);
wordNode.splitText(match[0].length);
@eirenik0
eirenik0 / fabfile.py
Last active August 29, 2015 14:15 — forked from dreamiurg/fabfile.py
from __future__ import with_statement
from fabric.api import local, settings, abort, run, cd, env, sudo
from fabric.colors import green as _green
from fabric.colors import yellow as _yellow
from fabric.colors import red as _red
from fabric.contrib.console import confirm
from fabric.contrib.project import rsync_project
from fabric.contrib.files import upload_template, exists
from fabric.operations import require
from fabric.context_managers import prefix

AngularJS best ressources

Following the AngularJS PARIS meetup (25/2 à 19h à Paris with @sampaccoud @dzen @_kemar @tchack13 @vinz et @revolunet)

Here's our best AngularJS ressources : twitter, github, articles & blogs. Please comment and add your good stuff !

from django.db.models.fields.related import ReverseSingleRelatedObjectDescriptor
def override_model_field(model, name, column, field):
"""Force override a field in a Django Model.
Usage: override_model_field(
MyModel, models.ForeignKey(OtherModel), 'other', 'other_id')
:type model: django.db.models.base.ModelBase
:type name: basestring
:type column: basestring
:type field: django.db.models.fields.Field
@eirenik0
eirenik0 / fractions.py
Created January 10, 2015 17:30
fractions for Problem Solving with Algorithms and Data Structures
import unittest
def gcd(m, n):
while m % n != 0:
oldm = m
oldn = n
m = oldn
n = oldm % oldn
return n
@eirenik0
eirenik0 / views.py
Last active August 29, 2015 14:08 — forked from mjumbewu/views.py
import re
from django.conf import settings
from django.core import cache as django_cache
from mock import patch
from rest_framework.permissions import SAFE_METHODS
from rest_framework.response import Response
class CachedResourceMixin (object):
@property
@eirenik0
eirenik0 / casscade_emul_trigger.sql
Created October 20, 2014 17:33
Emulate casscade update and delete
CREATE OR REPLACE FUNCTION casscade_func() RETURNS TRIGGER AS $$
DECLARE
exist boolean;
BEGIN
IF TG_OP = 'UPDATE' THEN
IF OLD.id <> NEW.id THEN
UPDATE tc_order SET customer_id=NEW.id WHERE customer_id=OLD.id;
END IF;
RETURN NEW;
ELSIF TG_OP = 'DELETE' THEN
@eirenik0
eirenik0 / gist:0064bf7911e1678fb96e
Created October 10, 2014 23:52 — forked from AJamesPhillips/gist:04f3047ca8770f4a3a58
Integration testing Scrapy spiders
import subprocess
import unittest
from scrapy.crawler import Crawler
from scrapy.utils.project import get_project_settings
from twisted.internet import reactor, task
from my_project.spiders.spider1 import Spider1
from my_project.spiders.spider2 import Spider2
@eirenik0
eirenik0 / login_required.py
Created September 21, 2014 07:33
Django LoginRequiredMixin
class LoginRequiredMixin(object):
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)