Skip to content

Instantly share code, notes, and snippets.

View KennFatt's full-sized avatar
🌠
Stargazing

Kennan Fattahillah KennFatt

🌠
Stargazing
View GitHub Profile
@KennFatt
KennFatt / sequence_pattern.c
Created October 24, 2019 04:54
Sequence odd pattern in C
#include <stdio.h>
unsigned int read_int();
/**
* 1 - 3 + 5 - 7 + 9 - 11 + 13 ... n
* Calculate total of the operation above.
*/
int main(int argc, char **argv)
{
@KennFatt
KennFatt / collection.dart
Created October 3, 2019 15:32
Collection introduction in dart 🎯
listCase() {
// List<dynamic>
List randomList = [
"There is a phrase",
234,
2.0094,
["Another random list", 98, 0x04]
];
// List<Object> - In this case, we use String object.
@KennFatt
KennFatt / string2hex.php
Created October 1, 2019 14:31
PHP String to hex.
<?php
declare(strict_types=1);
function string2hex(string $letter) : string {
$retVal = [];
for ($i = 0; $i < strlen($letter); ++$i) {
$retVal[$i] = dechex(ord($letter[$i]));
}
@KennFatt
KennFatt / chaining.php
Created September 28, 2019 05:09
PHP Encapsulation and Method chaining.
<?php
declare(strict_types=1);
class Car {
private $brandName = "";
private $doorsCount = 0;
private $fuelType = "";
@KennFatt
KennFatt / linkedlist.c
Created September 21, 2019 09:30
LinkedList in a nutshell.
#include <stdio.h>
#include <stdlib.h>
typedef struct Node_t Node;
typedef struct LinkedList_t LinkedList;
struct Node_t
{
int value;
Node* next;
@KennFatt
KennFatt / pom.xml
Created September 20, 2019 13:25
Build tag to generate executable jar file. Maven project only.
<build>
<plugins>
<plugin>
<!-- Jar builder plugin. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
@KennFatt
KennFatt / windowrenderer.c
Created September 18, 2019 02:42
SDL2 Create Window & Renderer, Load BMP image.
#include <SDL2/SDL.h>
int throw_sdl_err(const char* fmt)
{
SDL_LogError(
SDL_LOG_CATEGORY_APPLICATION,
fmt,
SDL_GetError()
);
return 3; // constant error code.
@KennFatt
KennFatt / mirrorlist
Created July 28, 2019 07:16
Pacman (Arch Linux package manager) mirrorlist for SEA region.
##
## Arch Linux repository mirrorlist
## Filtered by mirror score from mirror status page
## Generated on 2019-07-01
##
## Indonesia
Server = http://suro.ubaya.ac.id/archlinux/$repo/os/$arch
Server = http://mirror.poliwangi.ac.id/archlinux/$repo/os/$arch
@KennFatt
KennFatt / ambiguous_string.c
Last active July 20, 2019 15:50
Ambiguous char[] length that affect memory to allocate more spaces.
#include <stdio.h>
void _d(char val[], char identifier)
{
for (int i = 0; val[i] >= 0; ++i) {
printf("[#%c] val[%d]: (%c) -> %d;\n", identifier, i, val[i], val[i]);
}
}
int main(int argc, char **argv)
@KennFatt
KennFatt / struct_bitfield.c
Created July 16, 2019 18:11
C Bit-field in structures.
#include <stdio.h>
typedef struct {
// let this variable to store maximum 8-bit of value, that means this value ONLY accept any value from 0 to 255.
// if the value given is more than 255, so the program would capping its value.
unsigned char user_length:8;
} dat_t;
int main()
{