Skip to content

Instantly share code, notes, and snippets.

View jinliming2's full-sized avatar
🐍
Lost in the maze......

Liming Jin jinliming2

🐍
Lost in the maze......
View GitHub Profile
@jinliming2
jinliming2 / vscode-updater.sh
Last active July 9, 2023 15:03
Updater for VSCode on Linux. Check and Update VSCode for Linux. Support Visual Studio Code Stable and Visual Studio Code Insiders.
#!/bin/bash
# set -x
set -euo pipefail
# Required: curl and rsync
# Config
INSTALL_DIR=VSCode-linux-x64
INSTALL_PATH=/opt/${INSTALL_DIR}
@staaldraad
staaldraad / uid_awk.sh
Created December 12, 2017 14:06
Get the uid, gid and user groups without touching /etc/passwd or running the `id` command
awk -F: 'END {print "uid:"u" gid:"g" groups:"gg}{if($1=="Uid"){split($2,a," ");u=a[1]}if($1=="Gid"){split($2,a," ");g=a[1]}if($1=="Groups"){gg=$2}}' /proc/self/status
@staaldraad
staaldraad / awk_netstat.sh
Last active July 5, 2024 01:55
AWK to get details from /proc/net/tcp and /proc/net/udp when netstat and lsof are not available
# Gawk version
# Remote
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($3,index($3,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($3,i,2))}{print x":"strtonum("0x"substr($3,index($3,":")+1,4))}'
# Local
grep -v "rem_address" /proc/net/tcp | awk '{x=strtonum("0x"substr($2,index($2,":")-2,2)); for (i=5; i>0; i-=2) x = x"."strtonum("0x"substr($2,i,2))}{print x":"strtonum("0x"substr($2,index($2,":")+1,4))}'
# No Gawk
# Local
grep -v "rem_address" /proc/net/tcp | awk 'function hextodec(str,ret,n,i,k,c){
@mbinna
mbinna / effective_modern_cmake.md
Last active July 16, 2024 05:57
Effective Modern CMake

Effective Modern CMake

Getting Started

For a brief user-level introduction to CMake, watch C++ Weekly, Episode 78, Intro to CMake by Jason Turner. LLVM’s CMake Primer provides a good high-level introduction to the CMake syntax. Go read it now.

After that, watch Mathieu Ropert’s CppCon 2017 talk Using Modern CMake Patterns to Enforce a Good Modular Design (slides). It provides a thorough explanation of what modern CMake is and why it is so much better than “old school” CMake. The modular design ideas in this talk are based on the book [Large-Scale C++ Software Design](https://www.amazon.de/Large-Scale-Soft

@jaksi
jaksi / main.go
Created December 23, 2016 17:32
Go web server
package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"net/http"
@jlebon
jlebon / mock-mount.sh
Last active October 28, 2022 19:25
mock-mount.sh -- compat script for bwrap in mock
#!/bin/bash
set -euo pipefail
# This is a small compatibility script that ensures mock
# chroots are compatible with applications that expect / to
# be a mount point, such as bubblewrap.
cleanup() {
for mnt in sys proc; do
umount /mnt/mock-mount/$mnt
@mwender
mwender / impbcopy.m
Last active June 20, 2024 09:20
Command line copy an image file to the clipboard in Mac OS X. See first comment for install instructions.
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <unistd.h>
BOOL copy_to_clipboard(NSString *path)
{
// http://stackoverflow.com/questions/2681630/how-to-read-png-image-to-nsimage
NSImage * image;
if([path isEqualToString:@"-"])
{
// http://caiustheory.com/read-standard-input-using-objective-c