Skip to content

Instantly share code, notes, and snippets.

View dennis90's full-sized avatar
🚶‍♂️

Dennis Alves dennis90

🚶‍♂️
View GitHub Profile
<?php
class MinhaClasse {
private $data = array();
public function __set($name, $value) {
$this->data[$name] = $value;
}
public function __get($name) {
def namaTeam(number)
return number if (number % 7 != 0 and number % 5 != 0)
return "Team" if (number % 7 == 0 and number % 5 != 0)
return "Nama" if (number % 7 != 0 and number % 5 == 0)
"NamaTeam"
end
for i in 1..100
puts(namaTeam(i))
end
require "test/unit"
require "test/unit/ui/console/testrunner"
require "./namateam"
class NamaTeamTest < Test::Unit::TestCase
def test_multiplos_cinco()
assert_equal(namaTeam(5), "Nama")
assert_equal(namaTeam(10), "Nama")
assert_equal(namaTeam(15), "Nama")
assert_equal(namaTeam(55), "Nama")
class ClientForm(forms.ModelForm):
class Meta:
model = Client
fields = ('name', 'email')
def __init__(self, *args, **kwargs):
super(ClientForm, self).__init__(*args, **kwargs)
for field in iter(self.fields):
self.fields[field].widget.attrs.update({'class': 'form-control'})
<form method="POST">
{% csrf_token %}
{% for field in form %}
<div class="form-group">
<label for="id_{{ field.name }}">{{ field.label }}</label>
{{ field }}
</div>
{% endfor %}
<button type="submit" class="btn btn-primary">Gravar Cliente</button>
</form>
import re
from django.utils.safestring import mark_safe
from django import template
register = template.Library()
class_re = re.compile(r'(?<=class=["\'])(.*)(?=["\'])')
@register.filter
def add_class(value, css_class):
{% load add_class %}
<form method="post">
{% csrf_token %}
{{ form.non_field_errors }}
{% for field in form %}
<div class="form-group">
{{field.label_tag}}
{{field | add_class:"form-control"}}
{{field.errors}}
</div>
fileIO = BytesIO()
boletoPDF = pdf.BoletoPDF(fileIO)
boletoPDF.drawBoleto(boleto_dados)
boletoPDF.save()
fileIO.seek(0)
response = HttpResponse(fileIO.read(), content_type='application/pdf')
response['Content-Dispositon'] = 'attachment; filename=boleto.pdf'
@dennis90
dennis90 / set_wallpaper.py
Created August 7, 2017 16:04
Download wallpaper of the day at bing and set as wallpaper in xfce4
import os
import urllib
import json
from urllib.parse import urlparse
from urllib import request
"""
This script downloads bing's image of the day on the specified folder and set it as wallpaper in xfce4
"""
@dennis90
dennis90 / git_pushed_wrong_branch.md
Created October 8, 2017 18:56
What to do when you push to the wrong branch

Oh shit, I accidentally pushed to the wrong branch

# get the hashes from the wrong commits with git log

# then revert this commits:
git revert last-commit-hash

# create the correct branch and then checkout to then
git checkout -b right-branch