Skip to content

Instantly share code, notes, and snippets.

View cbertolasio's full-sized avatar

Cedric Bertolasio cbertolasio

View GitHub Profile
@cbertolasio
cbertolasio / DateTimeHelper.cs
Last active October 28, 2016 06:34
C# date time helper for parsing "date + time + timezone offset in minutes" into the date that "I" want... ## the basic premise is that... - the user will pick a date using a date picker - the user will pick a time using a time picker - the moment js library will calculate the users timezone offset in minutes - based on their current browser sett…
public static class DateTimeHelper
{
public static DateTimeOffset Combine(DateTimeOffset? originalDate, string timeString, int timeZoneOffsetInMinutes)
{
if(originalDate.HasValue)
{
return FromString(GetDateAsString(originalDate.Value.Date, timeString, timeZoneOffsetInMinutes));
}
else
{
@cbertolasio
cbertolasio / formatFilenameUsingDateTime.py
Created January 30, 2018 20:06
Format a string using datetime parts in python
#assuming the date is 25-JAN-2018 at 01:30:52
#the code below shouldPrint "AllPivots_20180125_0130"
from datetime import datetime
current = datetime.utcnow()
print(current)
year = str(current.year)
month = str(current.month).zfill(2)
day = str(current.day).zfill(2)
hours = str(current.hour).zfill(2)
@cbertolasio
cbertolasio / dopTablesInBulk.sql
Created February 2, 2018 17:01
cursor to drop tables matching a given name in sql server
select name
from [tst-IrrigationReporting].sys.tables
where name like 'YourTableName_2018%'
-- and is_ms_shipped = 0;
DECLARE @cmd varchar(4000)
DECLARE cmds CURSOR FOR
SELECT 'drop table [' + Table_Name + ']'
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_Name LIKE 'YourTableName_2018%'
@cbertolasio
cbertolasio / sql_table_rowCounts.sql
Created February 6, 2018 05:41
a way to get row counts and table size for a given sql db
-- https://blog.sqlauthority.com/2017/05/25/sql-server-simple-query-list-size-table-row-counts/
USE [YourDBName] -- replace your dbname
GO
SELECT
s.Name AS SchemaName,
t.Name AS TableName,
p.rows AS RowCounts,
CAST(ROUND((SUM(a.used_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS Used_MB,
CAST(ROUND((SUM(a.total_pages) - SUM(a.used_pages)) / 128.00, 2) AS NUMERIC(36, 2)) AS Unused_MB,
CAST(ROUND((SUM(a.total_pages) / 128.00), 2) AS NUMERIC(36, 2)) AS Total_MB
@cbertolasio
cbertolasio / getSpidLastBatch.sql
Created February 15, 2018 23:31
gets the last sql command issued by a spid
sp_who2
DECLARE @sqltext VARBINARY(128)
SELECT @sqltext = sql_handle
FROM sys.sysprocesses
WHERE spid = 62
SELECT TEXT
FROM sys.dm_exec_sql_text(@sqltext)
GO