Skip to content

Instantly share code, notes, and snippets.

View sytranvn's full-sized avatar
(n)

Sy Tran Dung sytranvn

(n)
View GitHub Profile
@sytranvn
sytranvn / clangd.md
Created September 28, 2023 05:11 — forked from Strus/clangd.md
How to use clangd C/C++ LSP in any project

How to use clangd C/C++ LSP in any project

tl;dr: If you want to just know the method, skip to How to section

Clangd is a state-of-the-art C/C++ LSP that can be used in every popular text editors like Neovim, Emacs or VS Code. Even CLion uses clangd under the hood. Unfortunately, clangd requires compile_commands.json to work, and the only way to painlessly generate it is to use CMake.

But what if I tell you you can quickly hack your way around that, and generate compile_commands.json for any project, no matter how compilcated? I have used that way at work for years, originaly because I used CLion which supported only CMake projects - but now I use that method succesfully with clangd and Neovim.

Method summary

Basically what we need to achieve is to create a CMake file that will generate a compile_commands.json file with information about:

@sytranvn
sytranvn / .bash_hooks
Created August 4, 2021 09:54
My .bashrc
export EDITOR=vim
export VISUAL=$EDITOR
@sytranvn
sytranvn / this-script.js
Last active November 20, 2020 15:15
List Postgres views, mviews depend on some other objects
#!/usr/bin/env node
/**
*******************************
* Copyright 2020 sytranvn *
* License: MIT License *
*******************************
*/
const { exit } = require('process')
const {promises } = require('fs')
@sytranvn
sytranvn / environment-variables-jekyll-templates.md
Created November 13, 2020 15:46 — forked from nicolashery/environment-variables-jekyll-templates.md
Make environment variables available in Jekyll Liquid templates

Environment variables in Jekyll templates

This is one way to pass some data (API tokens, etc.) to your Jekyll templates without putting it in your _config.yml file (which is likely to be committed in your GitHub repository).

Copy the environment_variables.rb plugin to your _plugins folder, and add any environment variable you wish to have available on the site.config object.

In a Liquid template, that information will be available through the site object. For example, _layouts/default.html could contain:

@sytranvn
sytranvn / jsonmin
Created October 1, 2020 06:32
Minify json to 1 line
#!/usr/bin/env bash
# by Jamie Tanna
python -c $'import json\nimport sys\nwith open(sys.argv[1], "r") as f: print(json.dumps(json.load(f)))' $1
@sytranvn
sytranvn / utils.h
Created August 18, 2020 03:52
Interesting C++ utils from V8 source code
// v8/utils
inline int HexValue(uc32 c) {
c -= '0';
if (static_cast<unsigned>(c) <= 9) return c;
c = (c | 0x20) - ('a' - '0'); // detect 0x11..0x16 and 0x31..0x36.
if (static_cast<unsigned>(c) <= 5) return c + 10;
return -1;
}
@sytranvn
sytranvn / trasfer.sh
Last active June 10, 2020 05:33
Sync home data
#!/usr/bin/env sh
# USAGE: transfer.sh [--ignore-existing] [user@]host[:port] <source> <destination>
ie=""
if [ "$1" = "--ignore-existing" ]; then
ie="$1"
shift
fi
@sytranvn
sytranvn / README.md
Created May 13, 2020 05:43 — forked from joyrexus/README.md
collapsible markdown

collapsible markdown?

CLICK ME

yes, even hidden code blocks!

print("hello world!")
const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const LOOPS = process.env.LOOPS || 2;
// start mesuring time
const hrstart = process.hrtime()
for (i=1; i <= LOOPS; i++) {
const index = i;
@sytranvn
sytranvn / main.py
Created February 20, 2020 10:15
sheets2html
from xlsx2html.core import worksheet_to_data, render_data_to_html
from openpyxl import load_workbook
workbook = load_workbook('input.xlsx')
for i, ws in enumerate(workbook.worksheets):
data = worksheet_to_data(ws)
html = render_data_to_html(data)
output = open('output_%s.html' % i, 'w')
output.write(html)