Skip to content

Instantly share code, notes, and snippets.

View plamentotev's full-sized avatar

Plamen Totev plamentotev

View GitHub Profile
@plamentotev
plamentotev / HelloWorld.java
Last active May 11, 2024 16:05
Sample application that uses JEP 454: Foreign Function & Memory API to create simple text UI with ncurses. Demo: https://gist.github.com/plamentotev/fff031eca3722df792db86096e238d02?permalink_comment_id=5043190#gistcomment-5043190
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.SymbolLookup;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
public class HelloWorld {
public static void main(String[] args) throws Throwable {
// Arena handles the lifecycle of native memory segments.
@plamentotev
plamentotev / WelcomeWindow.cs
Created February 17, 2024 17:35
Simple example that shows how to display an editor window on Unity startup.
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
// The static constructor is called before the class is used,
// but there is no guarantee when this would happen.
// InitializeOnLoad ensures that it is called when Unity loads
// or when the scripts are reloading.
[InitializeOnLoad]
public class WelcomeWindow : EditorWindow
@plamentotev
plamentotev / jq_cheat_sheet.adoc
Last active October 7, 2024 12:53
jq Cheat Sheet

jq Cheat Sheet

jq is useful utility, but I use it infrequently and each time I have to check what was the filters syntax. This cheat sheet helps we to recall what is the expression that I need. Hopefully it would help others too. For full guide refer to the official jq manual.

All the jq you (usually) need

Given the following JSON:

Hello, Diagrams!

GitHub recently added support for including Mermaid diagrams in Markdown files. The good news is that it works for AsciiDoc files as well. Here is an example:

sequenceDiagram
    participant Alice
    participant Bob
@plamentotev
plamentotev / commit-msg
Last active February 14, 2021 12:50
Git hook that checks if an issue was linked to the commit. If not, adds default issue reference and marks the commit as draft. To use - save as .git\hooks\commit-msg and make it executable
#!/usr/bin/bash
# Git hook that checks if an issue was linked to the commit.
# If not, adds default issue reference and marks the commit as draft.
ISSUE_KEYWORD='JIRA'
DEFAULT_ISSUE='NA'
DRAFT_KEYWORD='DRAFT'
# File containing the commit message is passed as first argument
@plamentotev
plamentotev / logr.py
Last active October 31, 2018 19:38
Very simple (and even more insecure) logging service. Just send POST request to PORT (8000 by default) and the service will log its body into log file
import http.server
import logging
import socketserver
logging.basicConfig(filename='messages.log', format='%(levelname)s:%(asctime)s:%(message)s', level=logging.DEBUG)
class SimpleLoggingHandler(http.server.BaseHTTPRequestHandler):
def do_POST(self):
msg = self.rfile.read(int(self.headers['Content-Length'])).decode('UTF-8')
logging.info(msg)
@plamentotev
plamentotev / migrate-tags.sh
Last active April 20, 2020 13:30
🇬🇧 When Maven was migrated from SVN to Git the tags didn't pointed to the master, but to a parallel history. This script helped with creating new tags that point to master. 🇧🇬 При мигрирането на Maven от SVN към Git таговете сочеха не към основната история, а към нейни разклонения. Този скрипт помогна да се създадат нови тагове.
for d in plugins/maven-*; do
pushd "${d}" > /dev/null
for tag in $(git tag); do
commit_sha=$(git rev-list -n1 "refs/tags/${tag}")
commit_message=$(git show --quiet --pretty="format:%B" "${commit_sha}")
tree_sha=$(git show --quiet --pretty="format:%T" "${commit_sha}")
# checking if the tag is reachable from master so the script could be ran multiple times.
if $( git merge-base --is-ancestor "${tag}" master ) ; then

На упражненията стана въпрос за String.Join и реализирахме нещо подобно. Интересно е да видим изходния код на метода, написан от Miscrosoft 😄

public static String Join(String separator, params Object[] values) {
    if (values==null)
        throw new ArgumentNullException("values");
    Contract.EndContractBlock();

    if (values.Length == 0 || values[0] == null)