Skip to content

Instantly share code, notes, and snippets.

@mloza
mloza / ForeignMemory.java
Last active February 24, 2020 08:28
Gist dla wpisu na temat nowości w Javie 14 znajdującego się pod adresem https://blog.mloza.pl/java-14-co-nowego-w-kolejnym-wydaniu/
VarHandle intHandle = MemoryHandles.varHandle(int.class,
ByteOrder.nativeOrder());
try (MemorySegment segment = MemorySegment.allocateNative(100)) {
MemoryAddress base = segment.baseAddress();
for (int i = 0; i < 25; i++) {
intHandle.set(base.addOffset(i * 4), i);
}
}
@mloza
mloza / LocalRecord.java
Last active January 19, 2020 23:40
Kod źródłowy do wpisu o Records Classes w Javie 14 znajdującego się pod adresem: https://blog.mloza.pl/java-14-record-classes/
public static void localRecord() {
String persons = """
Java,Developer,29
Python,Developer,25
John,Doe,65
""";
record LocalPerson(String firstName, String lastName, int age) {
LocalPerson(String[] data) {
this(data[0], data[1], Integer.parseInt(data[2]));
<?php
add_action('login_enqueue_scripts', function() { ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png);
width: 185px;
height: 185px;
background-size: initial;
}
</style>
@mloza
mloza / HtmlMailService.java
Last active December 15, 2019 19:10
Przykłady kodu do wpisu o Spring Mail znajdującego się pod adresem: https://blog.mloza.pl/spring-mail-spring-boot-latwe-wysylanie-maili-z-aplikacji-w-javie/
public void sendHtmlEmail(String to, String subject, String content) {
MimeMessage mail = javaMailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(mail, true);
helper.setTo(to);
helper.setFrom("Blog example <from@email.com>");
helper.setSubject(subject);
helper.setText(content, true);
} catch (MessagingException e) {
e.printStackTrace();
@RequestMapping("/path/{id}")
@ResponseBody
public String pathVariable(@PathVariable String id) {
return String.format("Wartość zmiennej id = %s", id);
}
@mloza
mloza / Main.java
Last active December 13, 2019 14:04
@SpringBootApplication
@Controller
public class Main {
@RequestMapping("/")
@ResponseBody
public String mainPage() {
return "Hello World!";
}
@Service
public class HelloService {
public String getHello() {
return "World";
}
}
@mloza
mloza / Main.java
Last active December 1, 2019 19:28
@EnableAutoConfiguration
@ComponentScan
@EnableJpaRepositories(basePackageClasses = TaskRepository.class)
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
#!/bin/bash
if [ -z "${CODEBUILD_RESOLVED_SOURCE_VERSION:-}" ]; then
{
echo "Error: CODEBUILD_RESOLVED_SOURCE_VERSION is not set"
} >&2
exit 1
else
echo "Resolved hash: ${CODEBUILD_RESOLVED_SOURCE_VERSION}"
fi
@mloza
mloza / PatternMatching.java
Last active November 3, 2019 17:11
Przykłady do wpisu o nowej składni switch w Javie 13
String formatted =
switch (obj) {
case Integer i -> String.format("int %d", i);
case Byte b -> String.format("byte %d", b);
case Long l -> String.format("long %d", l);
case Double d -> String.format("double %f", d);
case String s -> String.format("String %s, s);
default -> String.format("Object %s", obj);
};