Skip to content

Instantly share code, notes, and snippets.

View cansadadeserfeliz's full-sized avatar

Vera cansadadeserfeliz

  • Desparchado.co
  • Bogotá
View GitHub Profile
@cansadadeserfeliz
cansadadeserfeliz / subtitles_renamer.py
Last active March 9, 2023 00:28
Python Subtitles Renamer
import os
import re
import sys
import argparse
renaming_enabled = False
dir_path = os.path.dirname(os.path.realpath(__file__))
def rename_file(file_name, new_file_name):
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cansadadeserfeliz
cansadadeserfeliz / unsplash.js
Last active February 24, 2017 19:46
unsplash.js
function replace_unsplash_urls(width, height) {
var url = '';
var prev_url = '';
var links = document.querySelectorAll('#gridMulti a');
for(var i = 0; i < links.length; i++) {
var item = links.item(i);
url = links.item(i).style.getPropertyValue('background-image');
console.log(i, url)
if (url) {
@cansadadeserfeliz
cansadadeserfeliz / embassy_ru.py
Last active August 29, 2015 14:23
Prueba si hay citas disponibles de tipo "solicitud" para la Embajada Rusa en la Haya para el mes actual
import urllib2
from bs4 import BeautifulSoup
if BeautifulSoup(urllib2.urlopen(
'http://ambru.nl/priem_not/index.php'
).read()).findAll('td', {'class': 'tab4_3_not3'}):
print '\033[95m YAHOOO! \033[m\n'
@cansadadeserfeliz
cansadadeserfeliz / tests.py
Last active August 29, 2015 14:22
Edd a new field with Django WebTests
from webtest.forms import Field
# ...
extra_field = Field(form, tag='input', name='new_field', pos=0, value='new_value')
form.fields['new_field'] = [extra_field]
form['new_field'] = 'new_value'
form.field_order.append(('new_field', extra_field))
# How to add a form to formset: https://github.com/kmike/django-webtest/pull/17
from bs4 import BeautifulSoup
import bleach
def _delinkify(self, text):
"""
Converts <a href="http:my.url">Text</a> to
<a href="http:my.url">Text: http:my.url</a>
"""
soup = BeautifulSoup(text)
for link in soup.find_all('a'):
@cansadadeserfeliz
cansadadeserfeliz / tests.py
Last active September 8, 2024 23:22
Mock/replace timezone.now() with a custom date in Django unittes
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
from mock import patch
from django.test import TestCase
from django.utils import timezone
class DatesTestCase(TestCase):
@cansadadeserfeliz
cansadadeserfeliz / tests.py
Last active August 29, 2015 14:13
File attachments for Django test
from django.core.files.uploadedfile import SimpleUploadedFile
class UploadTestCase(TestCase):
def test_can_upload_file(self):
self.client.logout()
self.client.login(username='[email protected]', password='demo')
attachment = SimpleUploadedFile('attachment.pdf', 'file_content', content_type='application/pdf')
response = self.client.post(
@cansadadeserfeliz
cansadadeserfeliz / pre-commit.sh
Last active August 29, 2015 14:12 — forked from guilherme/gist:9604324
pre-commit hook for git
#!/bin/bash
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
consoleregexp='console.log'
printregexp='print '
# CHECK
@cansadadeserfeliz
cansadadeserfeliz / views.py
Last active August 29, 2015 14:11
Generate .zip file in Django
import os
import zipfile
import cStringIO as StringIO
class ContractDownloadGalleryDetailView(LoginRequiredMixin, DetailView):
model = Contract
def render_to_response(self, context, **httpresponse_kwargs):
contract = self.object