This file contains hidden or 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
@RestController | |
@RequestMapping("/data") | |
public class DataController { | |
@GetMapping(value = "/") | |
public ResponseEntity<tPage<T>> paginate(Pageable pageable) { | |
List<T> listFromSource = source.getList(); | |
Page<T> page = PaginationUtil.paginateList(pageable, listFromSource); | |
return ResponseEntity.ok(page); | |
} |
This file contains hidden or 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
public final class PaginationUtil { | |
private PaginationUtil(){} | |
public static <T> Page<T> paginateList(final Pageable pageable, List<T> list) { | |
int first = Math.min(new Long(pageable.getOffset()).intValue(), list.size());; | |
int last = Math.min(first + pageable.getPageSize(), list.size()); | |
return new PageImpl<>(list.subList(first, last), pageable, list.size()); | |
} | |
} |
This file contains hidden or 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
return Stream.of(this.getStringA(), this.getStringB()) | |
.filter(Objects::nonNull) | |
.collect(Collectors.joining(" - ")); |
This file contains hidden or 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
if (this.getStringA() != null && this.getStringB() != null) { | |
return this.getStringA() + " - " + this.getStringB(); | |
} else if (this.getStringA() != null) { | |
return this.getStringA(); | |
} else if (this.getStringB() != null) { | |
return this.getStringB(); | |
} else { | |
return ""; | |
} |
This file contains hidden or 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
return this.getStringA() + " - " + this.getStringB(); |
This file contains hidden or 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
#!/usr/bin/env python | |
# coding: utf8 | |
import imp | |
import sys, os | |
module_name = sys.argv[1] | |
bits = module_name.split('.') | |
name = imp.find_module(bits[0])[1] | |
if len(bits) > 1: |
This file contains hidden or 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import json | |
cars = json.loads(open('./fixtures/fipe_carro.json').read()) | |
tree = {} | |
for v in cars: | |
for name in v['translated_names']: |
This file contains hidden or 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
def fib(quantidade): | |
a, b = 0, 1 | |
for i in xrange(quantidade): | |
yield b | |
a, b = b, a + b | |
class Fib(object): | |
def __init__(self, quantidade): |
This file contains hidden or 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
from functools import wraps | |
def cached_property(fn): | |
@wraps(fn) | |
def wrapper(self): | |
cache_var = '_%s' % fn.__name__ | |
if not hasattr(self, cache_var): | |
setattr(self, cache_var, fn(self)) | |
return getattr(self, cache_var) | |
return property(wrapper) |
This file contains hidden or 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: utf-8 -*- | |
from django.forms import ModelForm | |
from django import forms | |
from django.contrib.auth.models import Group, User | |
class GroupAdminForm(ModelForm): | |
class Meta: | |
model = Group | |
group_users = forms.ModelMultipleChoiceField(label=u'Usuários deste Grupo', queryset=User.objects.all()) |
NewerOlder