Skip to content

Instantly share code, notes, and snippets.

test
<ol><li><p>You will use Django fixtures, a feature to upload data from JSON. On Django workspace under folder <em>myapp</em>, create folder with name <strong><em>fixtures</em></strong></p><figure><img src="https://img-c.udemycdn.com/redactor/raw/create_lab_editor/2022-11-04_14-20-21-d9fde732955de2be0fb1489751dc1bdb.png" width="300px"></figure><p> </p><figure><img src="https://img-c.udemycdn.com/redactor/raw/create_lab_editor/2022-11-04_14-20-21-94bc3cb7fe582809bf8128af3297f264.png"></figure><figure><img src="https://img-c.udemycdn.com/redactor/raw/create_lab_editor/2022-11-04_14-20-22-21fb95f7b3eea3c8e6e64738650f96fe.png" width="300px"></figure></li><li><p>Download initial JSON&nbsp;data file from task's asset and upload it into Django workspace, folder fixtures</p><figure><img src="https://img-c.udemycdn.com/redactor/raw/create_lab_editor/2022-11-04_14-20-22-1dbdcb6470cac6c0049954ad37f77730.png" width="300px"></figure><figure><img src="https://img-c.udemycdn.com/redactor/raw/create_lab_editor/2022-11-04_14-2
<ol><li><p>Create a Python data model with the name <strong>CarManufacturer</strong>. Edit file <em>myapp/models.py </em>and add the following code</p><pre class="prettyprint linenums">class CarManufacturer(models.Model):
&nbsp; &nbsp; name = models.CharField(max_length=255)
&nbsp; &nbsp; origin_country = models.CharField(max_length=255)
&nbsp; &nbsp; description = models.TextField(max_length=4000)</pre><figure><img src="https://img-c.udemycdn.com/redactor/raw/create_lab_editor/2022-11-02_23-59-33-e2bbc68d358677718060cd50c8115f78.png"></figure></li><li><p>In the terminal, make sure you are in folder <em>~/code</em> by using the command <code>cd ~/code</code> </p><figure><img src="https://img-c.udemycdn.com/redactor/raw/create_lab_editor/2022-11-02_23-59-33-73b1272f0e5dc51bde51a3d9d20d4b34.png"></figure></li><li><p>Create the automatic Python-to-MySQL database migration using Django. Use command <code>python3 manage.py makemigrations</code></p><figure><img src="https://img-c.udemycdn.com/redactor/raw/create
@timpamungkas
timpamungkas / CryptographyApi.java
Created April 26, 2022 07:27
SampleAPI for RSA + AES encryption
package com.example.secure;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.ThreadLocalRandom;
import javax.crypto.BadPaddingException;
@timpamungkas
timpamungkas / Customer.java
Created April 26, 2022 07:25
Sample data to be encrypted
package com.example.secure;
import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@timpamungkas
timpamungkas / CryptographyService.java
Last active April 26, 2022 07:31
Cryptography service for AES / RSA encryption / decryption
package com.example.secure;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
@timpamungkas
timpamungkas / LoanUdtf.java
Last active April 25, 2022 07:51
Kafka KsqlDB UDTF (tabular function)
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
import org.apache.kafka.connect.data.Schema;
import org.apache.kafka.connect.data.SchemaBuilder;
import org.apache.kafka.connect.data.Struct;
import io.confluent.ksql.function.udf.UdfParameter;
@timpamungkas
timpamungkas / docker-compose.yml
Created April 22, 2022 01:47
Docker compose for kafka & ksqldb
version: "3"
networks:
kafka-net:
name: kafka-net
driver: bridge
services:
zookeeper:
image: docker.io/bitnami/zookeeper:3.8
@timpamungkas
timpamungkas / LoanUdf.java
Last active April 25, 2022 07:51
Kafka KsqlDB UDF (scalar function)
import io.confluent.ksql.function.udf.Udf;
import io.confluent.ksql.function.udf.UdfDescription;
import io.confluent.ksql.function.udf.UdfParameter;
@UdfDescription(name = "loan_installment", category = "LOAN", author = "Timotius Pamungkas", version = "1.0.0", description = "User defined function for sample scalar loan business logic.")
public class LoanUdf {
@Udf(description = "Estimate monthly loan installment for loan principal amount X, "
+ "with loan interest rate per year is Y %, " + "over loan period Z month(s), "
+ "roundest to 2 digit decimal. All parameters are mandatory and can only accept value greater than 1")
@timpamungkas
timpamungkas / build.gradle
Created April 21, 2022 10:14
Gradle file for kafka UDF (User Defined Function) - Spring Boot
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version "7.1.2"
}
group = 'com.course.kafka'
version = '4.0.0'
sourceCompatibility = '11'
repositories {