Skip to content

Instantly share code, notes, and snippets.

local.file_match "system" {
path_targets = [{
__address__ = "localhost",
__path__ = "/var/log/*log",
job = "varlogs",
stream = "stdout",
}]
}
loki.source.file "system" {
[Unit]
Description=Prometheus Node Exporter
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
@choonsiong
choonsiong / gist:b0747e8a23b9dd8cd24c6d01572b398f
Created October 18, 2025 04:18
Prometheus: /etc/systemd/system.d/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
@choonsiong
choonsiong / palindrome.cpp
Created May 27, 2020 16:45
Is palindrome
bool isPalindrome(int x) {
int originalNumber = x;
if (x < 0) {
return false;
}
// Reverse x
bool firstDigit = true;
int reversedNumber = 0;
@choonsiong
choonsiong / add_5_or_multiply_3.js
Created May 27, 2020 06:53
By starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite set of numbers can be produced. Write a function that, given a number, tries to find a sequence of such additions and multiplications that produces that number.
/*
By starting from the number 1 and repeatedly either adding 5 or multiplying
by 3, an infinite set of numbers can be produced. Write a function that,
given a number, tries to find a sequence of such additions and multiplications
that produces that number.
*/
function findSolution(target) {
function find(current, history) {
console.log("==> " + history);
if (current == target) {
@choonsiong
choonsiong / chessboard.js
Created May 26, 2020 07:20
Print an arbitrary length chessboard pattern
let size = 100;
let result = '';
for (let i = 1; i <= size; ++i) {
for (let j = 1; j <= size; ++j) {
if (i % 2 != 0) {
// odd row
if (j == 1) {
// first col
result += '_';
for (let i = 1; i <= 100; ++i) {
if (i % 3 == 0 && i % 5 == 0) {
console.log("FizzBuzz");
} else if (i % 3 == 0) {
console.log("Fizz");
} else if (i % 5 == 0) {
console.log("Buzz");
} else {
console.log(i);
}
@choonsiong
choonsiong / triangle.js
Created May 26, 2020 06:59
Output triangle
for (let i = 1; i <= 7; ++i) {
let ch = "#";
for (let j = 1; j < i; ++j) {
ch = ch.concat("#");
}
console.log(ch);
}
@choonsiong
choonsiong / diagonal_stars.java
Created May 23, 2020 08:37
Print diagonal stars
public static void printSquareStar(int number) {
if (number < 5) {
System.out.println("Invalid Value");
return;
}
for (int i = 1; i <= number; i++) {
for (int j = 1; j <= number; j++) {
if (i == 1 || i == number) {
System.out.print("*");
@choonsiong
choonsiong / prime_factor.java
Created May 23, 2020 04:43
Find prime factor of a given number
// Calculate the prime factor of a given number.
public static int getLargestPrime(int number) {
int largestPrime = -1;
if (number == 0 || number == 1 || number < 0) {
return -1;
}
if (number == 2 || number == 3) {
return number;