Skip to content

Instantly share code, notes, and snippets.

View dk949's full-sized avatar

David K dk949

View GitHub Profile
@dk949
dk949 / ping.c
Last active December 14, 2021 15:47
Shortest ping implementation (that I could come up with)
long t[7]={2};main(int d,char**r){!(d==2&&inet_aton(r[1],&d)&&(t[6]=socket(2,2,1))>=0)&&raise(15);while(1)clock_gettime(0,&(t[2]))||((((unsigned*)t)[1]=d)&&(sendto(t[6],"\b\0\0\0\0\0\0\0",8,0,&t,16))<=0&&raise(15))||((recvfrom(t[6],r[1],8,0,0,0))<=0&&raise(15))||((r[1][0]!=0)&&raise(15))||clock_gettime(0,&(t[4]))||(printf("%fms\n",((t[4]-t[2])+(t[5]-t[3])/1e6))&&sleep(1));}
@dk949
dk949 / __description__
Last active February 25, 2025 10:50
Implementation of currying in c++
create a curried function out of a regular function

How to cmake

NOTE: You can also take a look at this cmake c++ started project.

Starting

The bare minimum cmake project contains one CMakeLists.txt file at the root of the project with the following code:

@dk949
dk949 / demangle.hpp
Last active February 25, 2025 10:50
Function to print c++ type names as plain text in gcc and clang
#ifndef UT_DEMANGLE_HPP
#define UT_DEMANGLE_HPP
/// Get type name as a string
/* Usage:
* #include "demangle.hpp"
* #include <iostream>
*
* namespace A::B {
@dk949
dk949 / comments_of_the_world.md
Last active March 14, 2025 19:59
Comments in different programming languages

Comments in different programming languages

This document lists comment styles and languages (and dialects) that use it. The list is based on the one used in NERD commenter.

Comment types are grouped by the types of symbols used. Each example is organised as a comment block followed by a list of languages.

Note1: the number of languages is quite large, and much of this

@dk949
dk949 / yaml2json.d
Created July 24, 2022 19:43
convert yaml to json
/+dub.json:
{
"authors": ["dk949"],
"copyright": "Copyright © 2022, dk949",
"dependencies": {"dyaml": "~>0.9.0"},
"description": "Convert yaml to json",
"license": "MIT",
"name": "yaml2json"
}
+/
@dk949
dk949 / getRandomArticle.py
Last active January 10, 2024 19:36
Python script to get random article titles from wikipedia
#!/usr/bin/env python
"""
Print some random article titles.
Usage: getRandomArticle.py [NUM]
NUM is the number of articles to get. Optional, default 20
"""
import sys
import requests
@dk949
dk949 / commands.md
Last active January 10, 2024 19:47
List of two letter *nix applications

Two letter applications

A large number of unix utilities have two letter names, like rm, mv, cp etc. You may have wandered which have already been used. There is a very high chance that all 676 possible ones have been used by someone, but here is a list of the ones found in the Arch repos.

Generated on 2024-01-10. 139 valid two letter commands were found. Code for generating this document is included as a comment at the end.

  • ab:
    • extra/apache
  • ag:
  • extra/the_silver_searcher
@dk949
dk949 / msgpack2json.d
Created September 3, 2022 08:33
COnvert msgpack to json
/+dub.json:
{
"authors": ["dk949"],
"copyright": "Copyright © 2022, dk949",
"dependencies": {"msgpack-d": "~>1.0.4"},
"description": "Convert msgpack to JSON",
"license": "MIT",
"name": "msgpack2json"
}
+/
@dk949
dk949 / wsl_debian_testing.md
Last active September 23, 2022 00:44
Debian testing on WSL