Skip to content

Instantly share code, notes, and snippets.

View JustinMcNamara74's full-sized avatar

Justin McNamara JustinMcNamara74

View GitHub Profile
@rkaneko
rkaneko / InstallingAgOnCentOS.md
Last active November 7, 2022 16:57
Installing ag: the silver searcher on CentOS.

Installing ag on CentOS

Prerequistes

  • libpcre
  • liblzma

Download, build and install

@JosiahSiegel
JosiahSiegel / monitor_progress.sql
Last active August 29, 2015 14:17
#MSSQL #Research Database Backup/Restore Progress
SELECT r.session_id,r.command,CONVERT(NUMERIC(6,2),r.percent_complete)
AS [PERCENT Complete],CONVERT(VARCHAR(20),DATEADD(ms,r.estimated_completion_time,GETDATE()),20) AS [ETA COMPLETION TIME],
CONVERT(NUMERIC(6,2),r.total_elapsed_time/1000.0/60.0) AS [Elapsed MIN],
CONVERT(NUMERIC(6,2),r.estimated_completion_time/1000.0/60.0) AS [ETA MIN],
CONVERT(NUMERIC(6,2),r.estimated_completion_time/1000.0/60.0/60.0) AS [ETA Hours],
CONVERT(VARCHAR(100),(SELECT SUBSTRING(TEXT,r.statement_start_offset/2,
CASE WHEN r.statement_end_offset = -1 THEN 1000 ELSE (r.statement_end_offset-r.statement_start_offset)/2 END)
FROM sys.dm_exec_sql_text(sql_handle)))
FROM sys.dm_exec_requests r WHERE command IN ('RESTORE DATABASE','BACKUP DATABASE')
@JosiahSiegel
JosiahSiegel / kill_spid.sql
Created March 23, 2015 16:52
#MSSQL Kill SPID, generate report
--run both commands
KILL 54;
--generates progress report
KILL 54 WITH STATUSONLY;
GO
@JosiahSiegel
JosiahSiegel / quick_analysis.sql
Last active May 31, 2024 14:15
#MSSQL #Research #OneStop Quick Analysis
SELECT
req.session_id AS [session],
ses.program_name AS [program],
jobs.name AS [job],
sqltext.TEXT AS [query],
DB_NAME(req.database_id) AS [database],
req.status,
wg.name AS [resource_group],
req.command,
CONVERT(varchar(10), (req.cpu_time / 86400000)) + ':' +
@JosiahSiegel
JosiahSiegel / missing_indexes.sql
Last active August 29, 2015 14:17
#MSSQL #Research Missing Indexes
SELECT
migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (
migs.user_seeks + migs.user_scans) AS
improvement_measure,
LEFT(PARSENAME(mid.statement, 1), 32) as object,
'CREATE INDEX [XK'
+ LEFT(PARSENAME(mid.statement, 1), 32)
+ MAX(CASE
WHEN ind.name LIKE '%[0-9]%' THEN
substring(ind.name, PatIndex('%[0-9]%', ind.name), len(ind.name))
@mattantonelli
mattantonelli / install_rbenv.sh
Last active August 29, 2015 14:21
How to install rbenv on CentOS
# If you are not using bash, you should take care to append the echo
# lines below to the appropriate shell_profile
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
exec $SHELL -l
@JosiahSiegel
JosiahSiegel / running_jobs.sql
Created May 29, 2015 16:02
#MSSQL #Research Active Jobs
SELECT
ja.job_id,
j.name AS job_name,
ja.start_execution_date,
ISNULL(last_executed_step_id,0)+1 AS current_executed_step_id,
js.step_name
FROM msdb.dbo.sysjobactivity ja
LEFT JOIN msdb.dbo.sysjobhistory jh
ON ja.job_history_id = jh.instance_id
JOIN msdb.dbo.sysjobs j
@JosiahSiegel
JosiahSiegel / log_activity.sql
Last active October 15, 2015 18:41
#MSSQL #Research Identify Transaction Log Activity
SELECT tst.[session_id],
s.[login_name] AS [Login Name],
DB_NAME (tdt.database_id) AS [Database],
tdt.[database_transaction_begin_time] AS [Begin Time],
tdt.[database_transaction_log_record_count] AS [Log Records],
tdt.[database_transaction_log_bytes_used] AS [Log Bytes Used],
tdt.[database_transaction_log_bytes_reserved] AS [Log Bytes Rsvd],
SUBSTRING(st.text, (r.statement_start_offset/2)+1,
((CASE r.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
@JosiahSiegel
JosiahSiegel / role_permissions.sql
Last active December 21, 2015 15:44
#MSSQL #Users #Research Admins, owners, users, roles, role members, and database permissions
-- server 'sysadmin'
SELECT name as 'sysadmin',type_desc,is_disabled
FROM master.sys.server_principals
WHERE IS_SRVROLEMEMBER ('sysadmin',name) = 1
ORDER BY name
-- database owner
select suser_sname(owner_sid) as 'owner'
from sys.databases
where name = DB_NAME()
@JosiahSiegel
JosiahSiegel / query_user.sql
Last active February 16, 2018 13:00
#LDAP Query user by sAMAccountName
SELECT $displayName, $cn FROM ROOTDSE
WHERE $objectClass='user' AND $objectCategory='Person'
AND $sAMAccountName='x0000000' --AND $cn='';