Skip to content

Instantly share code, notes, and snippets.

import java.io.*;
import java.util.regex.*;
public class AS32J {
static public String getContents(File file) {
StringBuffer contents = new StringBuffer();
try {
BufferedReader input = new BufferedReader(new FileReader(file));
try {
String line = null;
@edgartaor
edgartaor / utils.py
Last active August 29, 2015 14:17
Paginaton in nested view in ViewSet in custom route [Django - Rest Framework]
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, InvalidPage
from django.http import Http404
from django.utils import six
from rest_framework import pagination
def get_paginated_serializer(queryset, request, serializer_class, context,
page_size=50, page_kwarg='page', *args, **kwargs):
'''Get paginated serializer loaded with all the data'''
paginator = Paginator(queryset, page_size)
@edgartaor
edgartaor / filters.py
Last active March 31, 2020 08:52
Filter a field that contains any word in a phrase [Django-filters]
class ItemFilter(django_filters.FilterSet):
min_price = django_filters.NumberFilter(name='price', lookup_type='gte')
max_price = django_filters.NumberFilter(name='price', lookup_type='lte')
category = django_filters.CharFilter(name='category__slug', lookup_type='iexact')
title = django_filters.MethodFilter(name='title', action='icontains_any_word_title')
description = django_filters.MethodFilter(name='description', action='icontains_any_word_description')
class Meta:
model = Item
fields = ['category', 'min_price', 'max_price', 'negotiable', 'title', 'description']
@edgartaor
edgartaor / watermark.py
Created March 22, 2015 03:10
Watermarking for django-imagekit 3.2.6
# -*- coding: utf-8 -*-
#
# watermark processors for django-imagekit
# some inspiration from http://code.activestate.com/recipes/362879-watermark-with-pil/
#
from abc import abstractmethod, ABCMeta
from imagekit.lib import Image
from imagekit.lib import ImageDraw, ImageColor, ImageEnhance
from PIL import ImageFont
@edgartaor
edgartaor / ymp3.py
Created January 22, 2016 02:14
Download Youtube audio as mp3 in a specific directory within artist subfolder (if possible)
__author__ = 'EdgarT'
from __future__ import unicode_literals
import youtube_dl
import sys
class MyLogger(object):
def debug(self, msg):
print(msg)
@edgartaor
edgartaor / changeIP.sh
Last active March 17, 2016 03:11
Linux script to change IP on modem Thomson TG587/TG585
#!/bin/bash
set timeout 20
#Just to compare the old and new IP
echo Old IP:
curl "https://wtfismyip.com/text"
/usr/bin/expect << EOF
Ping all AWS EC2 IPs from http://ec2-reachability.amazonaws.com/
@edgartaor
edgartaor / Start-Vagrant.bat
Created September 24, 2016 01:14 — forked from Iristyle/Start-Vagrant.bat
Windows startup script to fire up a Vagrant VM safely on boot (using Run registry key for instance)
ECHO OFF
cd /d %~dp0
for /f "tokens=2* delims= " %%F IN ('vagrant status ^| find /I "default"') DO (SET "STATE=%%F%%G")
ECHO Close this window if it remains open, and http://localhost:8081 is responsive
IF "%STATE%" NEQ "saved" (
ECHO Starting Vagrant VM from powered down state...
vagrant up
) ELSE (
@edgartaor
edgartaor / docker-compose.yml
Created August 13, 2017 21:38
Wallabag + mariadb + redis docker-compose file
version: '2'
services:
wallabag:
image: wallabag/wallabag:latest
restart: always
ports:
- "8888:80"
tty: true
links:
- wallabag-db:wallabag-db
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
import argparse
import codecs
import configparser
import errno
import glob
from operator import itemgetter