Skip to content

Instantly share code, notes, and snippets.

@dtanphat9388
dtanphat9388 / rename-tmux-window.lua
Created August 4, 2024 04:50
auto set tmux window with last part of basedir
-- [[ set tmux window name by workspace ]]
local vimenter_group = vim.api.nvim_create_augroup("UserVimEnter", { clear = true })
vim.api.nvim_create_autocmd("VimEnter", {
group = vimenter_group,
callback = function()
local is_term_tmux = vim.env.TERM_PROGRAM == "tmux"
if not is_term_tmux then return end
local function get_last_directory(path)
path = path:gsub("[/\\]+$", "") -- Remove trailing slashes
return path:match("([^/\\]+)$") -- Capture the last directory name
@dtanphat9388
dtanphat9388 / nvim-tree.lua
Created July 30, 2024 18:17
remove range of selected files in nvim-tree
local function on_attach(bufnr)
local api = require("nvim-tree.api")
local core = require("nvim-tree.core")
local utils = require("nvim-tree.utils")
-- NOTE: set nvim-tree.ui.confirm.remove = false to take effect
local function remove_range_nodes()
local nodes = utils.get_nodes_by_line(api.tree.get_nodes().nodes, core.get_nodes_starting_line())
local lines = {}
if vim.fn.mode() == "v" or vim.fn.mode() == "V" then
@dtanphat9388
dtanphat9388 / mapper.js
Last active July 17, 2024 09:46
mapper object key in javascript
/*
FUNCTION DESIGN
Requirement:
- not change source object
Features:
- mapping
- include/exclude
@dtanphat9388
dtanphat9388 / .mongodb
Last active April 21, 2022 07:59
mongodb excecises
use('test');
const aggregation = [
// 32. Write a MongoDB query to find the restaurant name, borough, longitude and latitude and cuisine for those restaurants which contain 'Mad' as first three letters of its name. Go to the editor
// 31. Write a MongoDB query to find the restaurant name, borough, longitude and attitude and cuisine for those restaurants which contains 'mon' as three letters somewhere in its name. Go to the editor
// 30. Write a MongoDB query which will select the restaurant Id, name and grades for those restaurants which returns 0 as a remainder after dividing the score by 7. Go to the editor
@dtanphat9388
dtanphat9388 / process.js
Created December 11, 2018 09:39
draw circle process indicator by canvas
let canvas = document.querySelector('#canvas'); // id of canvas element
let ctx = canvas.getContext('2d')
ctx.lineWidth = 10;
ctx.lineCap = "round"
let process = 0
let middle = canvas.width * 0.5;
function draw(process) {
console.log(process)

diagram

  1. tạo payment request
    let paymentReq = new PaymentRequest([paymentMethod], details, options)
    • paymentMethod: app defined
    • details: popup for user select
    • options: app defined
/*
USE LIBRARY
*/
// b1: use library LiquidCrystal
#import <LiquidCrystal.h>
// b2: khởi tạo biến chứa thông tin các pin
// chọn 1 trong các khởi tạo sau:
@dtanphat9388
dtanphat9388 / Electron-Request.js
Last active April 27, 2018 05:43
Request data in Electron
import {app, BrowserWindow, net} from 'electron';
function _setup() {
// ...
/** get data for app */
let _strResult = '';
let jsonResult;
let req = net.request({url: 'https://jsonplaceholder.typicode.com/users'})
.on('response', res => {
@dtanphat9388
dtanphat9388 / commands.txt
Last active April 22, 2018 02:58
generate ssl keys
openssl req -sha256 -nodes -newkey rsa:2048 -nodes -keyout myserver.key -out server.csr -subj "/C=GB/ST=Yorks/L=York/O=MyCompany Ltd./OU=IT/CN=mysubdomain.mydomain.com"
@dtanphat9388
dtanphat9388 / cloudSettings
Last active May 1, 2021 20:02
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-05-01T20:02:30.246Z","extensionVersion":"v3.4.3"}