Skip to content

Instantly share code, notes, and snippets.

View iAnatoly's full-sized avatar

Anatoly Ivanov iAnatoly

View GitHub Profile
@iAnatoly
iAnatoly / swap.sh
Created October 14, 2019 18:54
oneliner to investigateprocess swap usage
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
@iAnatoly
iAnatoly / json-to-sqlite.md
Last active December 24, 2022 19:06
Convert json to a sqlite database for querying

Sometimes, you need to quickly dump a json file into sqlite, just to run some queries on it. This is a two-step process:

1. convert json to csv

cat file.json | jq -r '.data | map([.field1, .field2, .field3] | @csv)| join("\n")' > file.csv

1a. add headers line into your csv file, i.e.

@iAnatoly
iAnatoly / gist:bff5274bd2730b1a4801cdb6cb152fa1
Created February 2, 2019 20:21
Fixing ubuntu 18.10 lock screen issue
# the issue is siimple misconfigurations of gdm3
# the solution is to reinstall it, or better yet - switch to lightdm:
sudo apt remove gdm3 && dpkg-reconfigure lightdm
#
# or reinstall gdm3, it is up to you.
#!/bin/bash
#
# based off https://developer.atlassian.com/blog/2016/02/best-way-to-store-dotfiles-git-bare-repo/
#
git clone --bare git@github.com:iAnatoly/homedot.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
config checkout
@iAnatoly
iAnatoly / import-hashes.ps1
Last active June 19, 2018 20:43
How to upload 501M SHA1 hashes into a SQL database
# How to upload 501M SHA1 hashes into a SQL database
#
# Based on:
# https://blog.netnerds.net/2015/01/powershell-high-performance-techniques-for-importing-csv-to-sql-server/
# https://gallery.technet.microsoft.com/scriptcenter/Import-Large-CSVs-into-SQL-216223d9
#
# Database variables
$sqlserver = "YOUR_SERVER"
$database = "YOUR_DATABASE"
$table = "YOUR_TABLE"
@iAnatoly
iAnatoly / tweak.sh
Created June 15, 2017 12:58
MacOS tweaks
# override DHCP hostname assignment
sudo scutil --set HostName myhostname.domain.local
# tweak network
cat >> /etc/sysctl.conf <<EOF
# OSX default of 3 is not big enough
net.inet.tcp.win_scale_factor=8
# increase OSX TCP autotuning maximums
net.inet.tcp.autorcvbufmax=33554432
net.inet.tcp.autosndbufmax=33554432
@iAnatoly
iAnatoly / generate.sh
Created June 15, 2017 12:50
Interruptible script generating pre-defined number of random files
#!/bin/bash
TARGET_FILE_NUM=10000
CURRENT_FILE_NUM=`ls -l | wc -l`
FILES_TO_GENERATE=$((TARGET_FILE_NUM - CURRENT_FILE_NUM))
MAX_FILE_SIZE=8192
FILE_NAME_PREFIX="test_"
if [[ $FILES_TO_GENERATE -lt 0 ]]; then
echo "We already have $CURRENT_FILE_NUM files, no need to generate more"
@iAnatoly
iAnatoly / reclaimWindows10.ps1
Created January 7, 2017 19:54 — forked from alirobe/reclaimWindows10.ps1
"Reclaim Windows 10" turns off a bunch of unnecessary Windows 10 telemetery, removes bloatware, and privacy invasions. Review and tweak before running. Scripts for reversing are included and commented. Fork via https://github.com/Disassembler0 (different defaults)
##########
# Win10 Initial Setup Script
# Author: Disassembler <disassembler@dasm.cz>
# Version: 1.7, 2016-08-15
# dasm's script: https://github.com/Disassembler0/Win10-Initial-Setup-Script/
# THIS IS A PERSONALIZED VERSION
# This script leaves more MS defaults on, including MS security features.
# Tweaked based on personal preferences for @alirobe 2016-11-16 - v1.7.1
@iAnatoly
iAnatoly / base64
Created August 4, 2016 17:55
One-liners encoding and decoding Base64 in powershell
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("SecretMessage"))
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String("U2VjcmV0TWVzc2FnZQ=="))
@iAnatoly
iAnatoly / gist:a9a8c7fc30c5b5b075aa67d0122c2280
Created August 4, 2016 17:33
One-liner to generate password in PowerShell
[reflection.assembly]::LoadWithPartialName("System.Web")
[System.Web.Security.Membership]::GeneratePassword(32,4)