Skip to content

Instantly share code, notes, and snippets.

View PetarKirov's full-sized avatar

Petar Kirov PetarKirov

View GitHub Profile
@PetarKirov
PetarKirov / range_primitives_example.d
Last active September 27, 2020 18:23
Example usage of D range primitives
module range_primitives_example;
/++
Takes a slice of the first `n` elements from `input` and advances it by the
same amount.
+/
inout(int[]) readN_version1(ref inout(int)[] input, size_t n)
{
auto result = input[0 .. n];
input = input[n .. $];
@PetarKirov
PetarKirov / global-immutable-aa-example.d
Created September 23, 2020 19:54
Global immutable associative array variables
void main() {}
immutable string[ubyte] valueTypes;
// This is a shared module constructor. Code in this block will be executed
// exactly once at application startup. It is similar to running code in the
// global scope in JavaScript. Shared module constructors are allowed to
// "mutate" immutable global variables in order to initialize them.
shared static this()
{
@PetarKirov
PetarKirov / enum-aa-example.d
Created September 23, 2020 19:11
Enum associative arrays
void main() {}
enum string[ubyte] valueTypes = [
0x7F: "i32",
0x7E: "i64",
0x7D: "f32",
0x7C: "f64"
];
pure unittest
@PetarKirov
PetarKirov / example.d
Last active September 2, 2020 17:35
Attaching UDAs to enum members in dlang
void main()
{
import std.stdio : writeln;
import std.traits : EnumMembers;
foreach (SymbolKind kind; [EnumMembers!SymbolKind])
kind.enumUdatoString.writeln;
`----------------------`.writeln;
@PetarKirov
PetarKirov / tree.d
Last active August 13, 2020 10:22
tree formatting
void main()
{
import std.json : parseJSON;
import std.stdio : writeln;
const parsed = mySampleJson.parseJSON;
const tree = parsed.jsonToTree;
(*tree).writeln;
}
@PetarKirov
PetarKirov / results.txt
Created June 7, 2020 21:01
Running Dub's testsuite on Android (under Termux) with LDC 1.22.0-beta2
[INFO] Running /data/data/com.termux/files/home/code/repos/dlang/dlang/dub/test/0-init-fail-json.sh...
[INFO] Running /data/data/com.termux/files/home/code/repos/dlang/dlang/dub/test/0-init-fail.sh...
[INFO] Running /data/data/com.termux/files/home/code/repos/dlang/dlang/dub/test/0-init-interactive.sh...
Package recipe format (sdl/json) [json]: Name [0-init-interactive]: Description [A minimal D application.]: Author name [u0_a160]: License [proprietary]: Copyright string [Copyright © 2020, author]: Add dependency (leave empty to skip) []: Successfully created an empty project in '/data/data/com.termux/files/home/code/repos/dlang/dlang/dub/test/0-init-interactive'.
Package successfully created in 0-init-interactive
[INFO] Running /data/data/com.termux/files/home/code/repos/dlang/dlang/dub/test/0-init-multi-json.sh...
Successfully created an empty project in '/data/data/com.termux/files/home/code/repos/dlang/dlang/dub/test/0-init-multi-pack'.
Package successfully cre
@PetarKirov
PetarKirov / azure.md
Last active April 9, 2020 09:53
Azure CLI tips

Useful Azure CLI commands

  • Register all Microsoft resource providers
    az provider list --query "[? starts_with(@.namespace, 'Microsoft')].namespace" -o tsv \
      | xargs -I{} sh -c 'echo "Registering provider {}" && az provider register -n {}'
@PetarKirov
PetarKirov / hello-node.Dockerfile
Created April 8, 2020 22:28
Test Node.js Docker container
ARG BASE_IMAGE=node:lts-alpine
FROM $BASE_IMAGE
WORKDIR /src
ENV HOST=0.0.0.0 PORT=8080
RUN echo $'\
"use strict";\n\
const http = require("http");\n\
const server = http.createServer((request, response) => {\n\ response.writeHead(200, {"Content-Type": "text/plain"});\n\
response.end("Hello, World!");\n\
});\n\
@PetarKirov
PetarKirov / test.asm
Last active April 9, 2020 09:22
dlang toStaticArray LDC 1.20.0 codegen with flags: `-O`
_Dmain:
push rax
mov dword ptr [rsp + 4], 7562337
lea rdi, [rip + .L.str.1]
lea rdx, [rsp + 4]
mov esi, 4
xor eax, eax
call printf@PLT
call void example.testSomeMore()@PLT
xor eax, eax
@PetarKirov
PetarKirov / index.js
Created February 17, 2020 18:57
List container registries of all GitLab projects of a given group
const axios = require('axios');
(async () => {
const token = '<INSERT YOUR PERSONAL ACCESS TOKEN HERE>';
const group = '<INSERT GITLAB GROUP NAME HERE>';
console.log(await main(group, token));
})();
async function main(group, token) {
const projects = await getGitlabProjects(group, token);