Skip to content

Instantly share code, notes, and snippets.

@mloza
mloza / ManyToMany.java
Created April 22, 2020 08:17
Kod źródłowy do wpisu o Spring Boot - Spring Data JPA część II: Powiązania między tabelami znajdującego się pod adresem https://blog.mloza.pl/spring-boot-spring-data-jpa-czesc-ii-powiazania-miedzy-tabelami/
@ManyToMany
private List<Project> projects;
@mloza
mloza / CredentialsProvider.java
Created April 21, 2020 19:06
Kod do postu o Google Cloud Storage znajdujący się pod adresem https://blog.mloza.pl/google-cloud-storage/
public class CredentialsProvider {
public static Credential authorize() {
try {
return GoogleCredential.fromStream(CredentialsProvider.class.getClassLoader()
.getResourceAsStream("client-secrets.json"))
.createScoped(Collections.singleton(StorageScopes.CLOUD_PLATFORM));
} catch (IOException e) {
Throwables.propagate(e);
}
return null;
@mloza
mloza / Auth.java
Created April 19, 2020 12:23
Kod do wpisu o Spring Boot Security znajdujący się pod adresem https://blog.mloza.pl/spring-security-w-spring-boot/
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/loggeduser").authenticated()
.and().formLogin();
}
@mloza
mloza / Fibonacci.java
Last active April 15, 2020 09:31
Kod do wpisu o ciekawych zastosowaniach streamów w Javie. Post znajduje się pod adresem https://blog.mloza.pl/ciekawe-przyklady-zastosowania-streamow-w-javie/
public class Fibonacci {
private static class FibonacciGenerator {
private BigInteger nMinusTwo = BigInteger.ONE;
private BigInteger nMinusOne = BigInteger.ZERO;
public BigInteger next() {
final BigInteger n = nMinusTwo.add(nMinusOne);
nMinusTwo = nMinusOne;
@mloza
mloza / migration.py
Created April 15, 2020 09:05
Kod do postu o dodawaniu nowej, unikalnej kolumny do istniejącej tabeli w Django znajdujący się pod adresem https://blog.mloza.pl/dodanie-unikalnej-kolumny-do-istniejacej-tabeli-w-django/‎
from __future__ import unicode_literals
import common.functions
from django.db import migrations, models
def uniquify_keys_for_events(apps, schema_editor):
events = apps.get_model("event", "Event").objects.all()
for event in events:
event.key = common.functions.generate_random_string_32()
event.save()
@mloza
mloza / args.py
Last active April 14, 2020 19:54
Kod źródłowy do postu na temat dodawania nowych poleceń w Django i manage.py znajdujący się pod adresem https://blog.mloza.pl/django-dodawanie-obslugi-nowych-komend-przez-manage-py
def add_arguments(self, parser):
parser.add_argument('-d', '--display',
action='store_true',
default=False,
dest='show',
help='display text')
@mloza
mloza / Column.java
Last active April 2, 2020 17:39
Kod źródłowy do wpisu o polach JSONB w PostgreSQL i mapowaniu ich na encje Hibernate oraz Spring Data JPA znajdujący się pod adresem: https://blog.mloza.pl/wsparcie-dla-pola-typu-jsonb-w-postgresql-dla-spring-data-jpa-hibernate/
@Column
@Type(type = "pl.mloza.hibernate.CustomType")
private JsonbObject jsonbObject;
@mloza
mloza / UploadController.java
Last active December 10, 2020 18:56
Kod źródłowy do wpisu o wysyłaniu plików na serwer za pomocą spring boota i javy znajdujący się pod adresem: https://blog.mloza.pl/wysylanie-plikow-na-serwer-przez-spring-boot/
@Controller
public class UploadController {
@PostMapping("/upload")
@ResponseBody // 1
public String handleFile(@RequestPart(name = "fileupload") MultipartFile file) { // 2
File uploadDirectory = new File("uploads");
uploadDirectory.mkdirs(); // 3
File oFile = new File("uploads/" + file.getOriginalFilename());
@mloza
mloza / ComponentScan.java
Last active March 21, 2020 08:34
Kod źródłowy do wpisu Spring Boot Widoki - https://blog.mloza.pl/spring-boot-widoki
@ComponentScan(basePackageClasses = {MainController.class, WebAppConfiguration.class})
@mloza
mloza / tests.py
Created March 21, 2020 07:45
Kod do wpisu Testy w Django z użyciem Selenium https://blog.mloza.pl/testy-w-django-z-uzyciem-selenium/
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
class AuthenticationTests(StaticLiveServerTestCase):
def __init__(self, methodName='runTest'):
super().__init__(methodName='runTest')