Skip to content

Instantly share code, notes, and snippets.

@pfrozi
pfrozi / query.sql
Created May 12, 2021 13:17
Get the statistics of the most executed queries on the Microsoft SQL Server Database.
SELECT TOP 100
DatabaseName = db_name(dest.dbid),
OBJECT_NAME(objectid) AS ObjectName,
last_execution_time,
execution_count,
total_cpu_time = total_worker_time / 1000,
avg_cpu_time = (total_worker_time / execution_count) / 1000.0,
min_cpu_time = min_worker_time / 1000.0,
max_cpu_time = max_worker_time / 1000.0,
last_cpu_time = last_worker_time / 1000.0,
@pfrozi
pfrozi / bash-to-zsh-hist.py
Created May 6, 2021 20:36 — forked from muendelezaji/bash-to-zsh-hist.py
Convert Bash history to Zsh history
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This is how I used it:
# $ cat ~/.bash_history | python bash-to-zsh-hist.py >> ~/.zsh_history
import sys
import time
@pfrozi
pfrozi / set-cron.md
Last active October 28, 2021 17:25
Setting up a cron job in linux

CRONTAB SYNTAX

m h d M w /directory/command output

{m h d M w} specify the time/date and recurrence of the job

  • m(inunte) h(our) d(ay) M(onth) (day of)w(eek)
  • {/directory/command} specifies the location and comand you want to run
  • {output} is a optional segment. It defines how system notifies the user of the job completion
@pfrozi
pfrozi / main.go
Created March 2, 2021 03:21
Truncate time from now
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now())
fmt.Println(time.Now().Truncate(24*time.Hour))
@pfrozi
pfrozi / copy.sh
Created March 1, 2021 15:23
Create image file from clipboard on ubuntu
xclip -selection clipboard -t image/png -o > 00-login.png
@pfrozi
pfrozi / create_job.sql
Created February 18, 2021 15:17
Create a new job on SQLServer
EXEC dbo.sp_add_job
@job_name = N'NameOfJob' ;
GO
EXEC sp_add_jobstep
@job_name = N'NameOfJob',
@step_name = N'Description of job step.',
@subsystem = N'TSQL',
@command = N'EXEC SP_MYJOB ''A'',''B'',''C'' ',
@retry_attempts = 5,
@retry_interval = 5 ;
@pfrozi
pfrozi / changechset.sh
Last active February 12, 2021 21:51
Change the charset of a file
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -i INPUT_FILE -e OUTPUT_CHARSET -o OUTPUT_FILE
@pfrozi
pfrozi / template.sh
Created February 12, 2021 03:55
Bash program template
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@pfrozi
pfrozi / find-and-move.sh
Last active November 18, 2020 13:34
Replace filename, foldername and file content from a path.
#!/usr/bin/env bash
# $1: base path
# $2: vendor name (lowercase)
# $3: new vendor name (lowercase)
# Sample: bash find-and-move.sh ~/workspace/company company company2
path=$1
vendor=$2
@pfrozi
pfrozi / create_complete.sh
Last active September 23, 2020 13:18
Create a SQL Server script with all new .sql files from branch_with_new_scripts
#!/bin/bash
script=scripts_complete.sql
rm -f $script
for item in $(git diff-tree --name-only --no-commit-id -r master branch_with_new_scripts | grep ".sql"); do
cat $item >> $script
echo >> $script
echo GO >> $script