mirror of
https://github.com/harish2704/dotFiles.git
synced 2026-09-10 15:21:09 +00:00
Compare commits
2
Commits
2e6e0a997d
...
544641f800
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
544641f800 | ||
|
|
55239d7801 |
+81
@@ -0,0 +1,81 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# ॐ Om Brahmarppanam ॐ
|
||||||
|
#
|
||||||
|
# csv-split-by-col.py
|
||||||
|
# Created at: Sat Jan 28 2023 19:43:44 GMT+0530 (GMT+05:30)
|
||||||
|
#
|
||||||
|
# Copyright 2023 Harish Karumuthil <harish2704@gmail.com>
|
||||||
|
#
|
||||||
|
# Use of this source code is governed by an MIT-style
|
||||||
|
# license that can be found in the LICENSE file or at
|
||||||
|
# https://opensource.org/licenses/MIT.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
import pandas as pd
|
||||||
|
import openpyxl
|
||||||
|
|
||||||
|
def pathToFilename(filePath):
|
||||||
|
return os.path.splitext(os.path.basename(filePath))[0]
|
||||||
|
|
||||||
|
# Shamelessly copied from https://stackoverflow.com/a/39530676/1677234
|
||||||
|
def autoWidth(worksheet):
|
||||||
|
for col in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column = col[0].column_letter # Get the column name
|
||||||
|
for cell in col:
|
||||||
|
try: # Necessary to avoid error on empty cells
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(str(cell.value))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2)
|
||||||
|
worksheet.column_dimensions[column].width = adjusted_width
|
||||||
|
|
||||||
|
def main(df, firstCol, secondCol, outputDir, fileName):
|
||||||
|
firstColUniq = df[firstCol].unique()
|
||||||
|
for i in firstColUniq:
|
||||||
|
subDf = df[ df[firstCol] == i ]
|
||||||
|
subDf = subDf.drop(firstCol, axis=1)
|
||||||
|
with pd.ExcelWriter('{0}/{1}_{2}.xlsx'.format(outputDir,fileName,i), engine='openpyxl') as writer:
|
||||||
|
# with pd.ExcelWriter('{0}/{1}_{2}.xlsx'.format(outputDir,fileName,i), engine='xlsxwriter') as writer: # Does not work with adjusted_width
|
||||||
|
secondColUniq = subDf[secondCol].unique()
|
||||||
|
for j in secondColUniq:
|
||||||
|
sheetDf = subDf[ subDf[secondCol] == j ]
|
||||||
|
sheetDf = sheetDf.drop(secondCol, axis=1)
|
||||||
|
sheetName = j[0:20]
|
||||||
|
sheetDf.insert(0, 'S.No', range(1, 1+len(sheetDf)))
|
||||||
|
sheet = sheetDf.to_excel(writer, sheet_name=sheetName, index=False)
|
||||||
|
writer.sheets[sheetName].header = sheetName
|
||||||
|
# auto_adjust_xlsx_column_width(sheetDf, writer, sheetName)
|
||||||
|
for _,sheet in writer.sheets.items():
|
||||||
|
autoWidth(sheet)
|
||||||
|
sheet.evenHeader.center.text = "&A - Page &[Page] of &N"
|
||||||
|
sheet.oddHeader.center.text = "&A - Page &[Page] of &N"
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog = 'Split CSV',
|
||||||
|
description = 'Split big CSV file to N-files with M-sheets per file by grouping first and second column option',
|
||||||
|
epilog = 'Text at the bottom of help')
|
||||||
|
parser.add_argument('filename')
|
||||||
|
parser.add_argument('-d', '--delimiter', default=',', help="Delimiter (default=',')")
|
||||||
|
parser.add_argument('-f', '--first-column', help="title of primary column based on which files will be split")
|
||||||
|
parser.add_argument('-s', '--second-column', help="title of second column based on which each sheets will be created in single file")
|
||||||
|
parser.add_argument('-o', '--output-dir', help="Output director default( './csvsplit.out')", default='./csvsplit.out')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
dataFrame = pd.read_csv(args.filename, sep=args.delimiter)
|
||||||
|
firstColumn = args.first_column or dataFrame.columns[0]
|
||||||
|
secondColumn = args.second_column or dataFrame.columns[1]
|
||||||
|
|
||||||
|
# TODO: mkdir -p
|
||||||
|
try:
|
||||||
|
os.mkdir(args.output_dir)
|
||||||
|
except FileExistsError as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
main( dataFrame, firstColumn, secondColumn, args.output_dir, pathToFilename(args.filename) )
|
||||||
@@ -307,12 +307,22 @@ phpdebugsrv(){
|
|||||||
php -S 127.0.0.1:8000 -d xdebug.mode=develop,debug -d xdebug.start_with_request=yes $@
|
php -S 127.0.0.1:8000 -d xdebug.mode=develop,debug -d xdebug.start_with_request=yes $@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Restart sound system
|
||||||
|
soundRestart(){
|
||||||
|
systemctl --user restart pipewire
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Run any application with ibus support
|
# Run any application with ibus support
|
||||||
ibusRun(){
|
ibusRun(){
|
||||||
env GTK_IM_MODULE=ibus QT_IM_MODULE=ibus XMODIFIERS=@im=ibus $@
|
env GTK_IM_MODULE=ibus QT_IM_MODULE=ibus XMODIFIERS=@im=ibus $@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Refresh font cache
|
||||||
|
fontCacheRefresh(){
|
||||||
|
fc-cache -f -v
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Setup autocomplete. run eval "$(THIS_FILE setup-autocomplete)"
|
# Setup autocomplete. run eval "$(THIS_FILE setup-autocomplete)"
|
||||||
setup-autocomplete(){
|
setup-autocomplete(){
|
||||||
|
|||||||
@@ -2,3 +2,4 @@
|
|||||||
./bin/hari-tools.sh
|
./bin/hari-tools.sh
|
||||||
./bin/bash-session
|
./bin/bash-session
|
||||||
./bin/ibus-next-engine.py
|
./bin/ibus-next-engine.py
|
||||||
|
./bin/csv-split-by-col.py
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ lvim.format_on_save = {
|
|||||||
lvim.leader = "space"
|
lvim.leader = "space"
|
||||||
-- add your own keymapping
|
-- add your own keymapping
|
||||||
lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
|
lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
|
||||||
|
lvim.keys.normal_mode['<C-p>'] = ":Telescope find_files<CR>"
|
||||||
|
|
||||||
-- lvim.keys.normal_mode["<S-l>"] = ":BufferLineCycleNext<CR>"
|
-- lvim.keys.normal_mode["<S-l>"] = ":BufferLineCycleNext<CR>"
|
||||||
-- lvim.keys.normal_mode["<S-h>"] = ":BufferLineCyclePrev<CR>"
|
-- lvim.keys.normal_mode["<S-h>"] = ":BufferLineCyclePrev<CR>"
|
||||||
@@ -74,15 +75,14 @@ lvim.builtin.treesitter.auto_install = true
|
|||||||
-- end
|
-- end
|
||||||
|
|
||||||
-- -- linters and formatters <https://www.lunarvim.org/docs/languages#lintingformatting>
|
-- -- linters and formatters <https://www.lunarvim.org/docs/languages#lintingformatting>
|
||||||
-- local formatters = require "lvim.lsp.null-ls.formatters"
|
local formatters = require "lvim.lsp.null-ls.formatters"
|
||||||
-- formatters.setup {
|
formatters.setup {
|
||||||
-- { command = "stylua" },
|
{
|
||||||
-- {
|
command = "prettier",
|
||||||
-- command = "prettier",
|
extra_args = { "--print-width", "100" },
|
||||||
-- extra_args = { "--print-width", "100" },
|
filetypes = { "typescript", "typescriptreact", "javascript", "javascriptreact" },
|
||||||
-- filetypes = { "typescript", "typescriptreact" },
|
},
|
||||||
-- },
|
}
|
||||||
-- }
|
|
||||||
-- local linters = require "lvim.lsp.null-ls.linters"
|
-- local linters = require "lvim.lsp.null-ls.linters"
|
||||||
-- linters.setup {
|
-- linters.setup {
|
||||||
-- { command = "flake8", filetypes = { "python" } },
|
-- { command = "flake8", filetypes = { "python" } },
|
||||||
@@ -109,6 +109,12 @@ lvim.builtin.treesitter.auto_install = true
|
|||||||
-- end,
|
-- end,
|
||||||
-- })
|
-- })
|
||||||
|
|
||||||
|
local actions = require("telescope.actions")
|
||||||
|
lvim.builtin.telescope.pickers.find_files.mappings = {
|
||||||
|
i = {
|
||||||
|
['<C-t>'] = actions.smart_send_to_qflist + actions.open_qflist,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
command! -nargs=+ Gr :silent execute 'grep! -nr "<args>" | copen'
|
command! -nargs=+ Gr :silent execute 'grep! -nr "<args>" | copen'
|
||||||
@@ -191,8 +197,26 @@ vmap <C-s> <Esc><c-s>gv
|
|||||||
imap <C-s> <Esc><c-s>
|
imap <C-s> <Esc><c-s>
|
||||||
nmap <C-PageUp> :BufferLineCyclePrev<CR>
|
nmap <C-PageUp> :BufferLineCyclePrev<CR>
|
||||||
nmap <C-PageDown> :BufferLineCycleNext<CR>
|
nmap <C-PageDown> :BufferLineCycleNext<CR>
|
||||||
|
|
||||||
|
let g:user_emmet_mode='inv'
|
||||||
|
let g:user_emmet_install_global = 0
|
||||||
|
autocmd FileType html,css,vue,jsx,php EmmetInstall
|
||||||
|
nmap <C-G> :execute 'Telescope live_grep default_text=' . expand('<cword>')<cr>
|
||||||
]])
|
]])
|
||||||
|
-- imap <C-E> <plug>(emmet-expand-abbr)
|
||||||
|
vim.keymap.set('i', '<C-E>', '<plug>(emmet-expand-abbr)')
|
||||||
|
|
||||||
|
vim.keymap.set('n', '<F5>', function() require('dap').continue() end)
|
||||||
|
vim.keymap.set('n', '<F10>', function() require('dap').step_over() end)
|
||||||
|
vim.keymap.set('n', '<F11>', function() require('dap').step_into() end)
|
||||||
|
vim.keymap.set('n', '<F12>', function() require('dap').step_out() end)
|
||||||
lvim.builtin.dap.active = true
|
lvim.builtin.dap.active = true
|
||||||
|
lvim.builtin.which_key.mappings["l"]["f"] = {
|
||||||
|
function()
|
||||||
|
require("lvim.lsp.utils").format { timeout_ms = 2000 }
|
||||||
|
end,
|
||||||
|
"Format",
|
||||||
|
}
|
||||||
|
|
||||||
local dap = require('dap')
|
local dap = require('dap')
|
||||||
dap.adapters.php = {
|
dap.adapters.php = {
|
||||||
@@ -212,7 +236,59 @@ dap.configurations.php = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lvim.plugins = {
|
lvim.plugins = {
|
||||||
{
|
{
|
||||||
"gpanders/editorconfig.nvim",
|
"gpanders/editorconfig.nvim",
|
||||||
|
},
|
||||||
|
{ 'mattn/emmet-vim' },
|
||||||
|
{
|
||||||
|
"tpope/vim-fugitive",
|
||||||
|
cmd = {
|
||||||
|
"G",
|
||||||
|
"Git",
|
||||||
|
"Gdiffsplit",
|
||||||
|
"Gread",
|
||||||
|
"Gwrite",
|
||||||
|
"Ggrep",
|
||||||
|
"GMove",
|
||||||
|
"GDelete",
|
||||||
|
"GBrowse",
|
||||||
|
"GRemove",
|
||||||
|
"GRename",
|
||||||
|
"Glgrep",
|
||||||
|
"Gedit"
|
||||||
},
|
},
|
||||||
|
ft = { "fugitive" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"iamcco/markdown-preview.nvim",
|
||||||
|
build = "cd app && npm install",
|
||||||
|
ft = "markdown",
|
||||||
|
config = function()
|
||||||
|
vim.g.mkdp_auto_start = 1
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"turbio/bracey.vim",
|
||||||
|
cmd = { "Bracey", "BracyStop", "BraceyReload", "BraceyEval" },
|
||||||
|
build = "npm install --prefix server",
|
||||||
|
lazy = true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kylechui/nvim-surround",
|
||||||
|
config = function()
|
||||||
|
require("nvim-surround").setup({
|
||||||
|
-- Configuration here, or leave empty to use defaults
|
||||||
|
})
|
||||||
|
end
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'rmagatti/auto-session',
|
||||||
|
-- cmd = { 'SaveSession', 'RestoreSession', 'RestoreSessionFromFile', 'DeleteSession', 'Autosession', },
|
||||||
|
config = function()
|
||||||
|
require("auto-session").setup {
|
||||||
|
log_level = "error",
|
||||||
|
auto_session_create_enabled = false,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user