Skip to content

Instantly share code, notes, and snippets.

View sbealer's full-sized avatar

Stephen Bealer sbealer

View GitHub Profile
@sbealer
sbealer / retail_454_calendar.sql
Last active October 4, 2019 22:30
Retail 4-5-4 calendar TSQL
USE YOURDB;
CREATE TABLE DBO.RETAIL_454_CALENDAR (RETAIL_DATE DATE, RETAIL_WEEK INT, RETAIL_YEAR INT);
TRUNCATE TABLE DBO.RETAIL_454_CALENDAR;
/* Do not pick an arbitrary start date. This script relies on the correct start date for Retail year 2012 */
DECLARE @BEGIN_DATE date = '29-Jan-2012'
DECLARE @END_DATE DATE = '01-May-2090'
DECLARE @WEEK_START_DATE DATE = @BEGIN_DATE;
DECLARE @DATES_TABLE TABLE (DT DATE);
@sbealer
sbealer / Franz Slack Dark Mod3z.txt
Last active December 3, 2018 20:20
Dark Theme for Franz Slack (Windows)
Save the contents of: https://raw.githubusercontent.com/artifex404/slack-dark-theme/master/custom.css into
C:\Users\%username%\AppData\Roaming\Franz\recipes\slack
Open this file: "C:\Users\%username%\AppData\Roaming\Franz\recipes\slack\webview.js"
Find the line that has the code: "Franz.injectCSS(_path2.default.join(__dirname, 'service.css'));"
Under that line add: Franz.injectCSS(_path2.default.join(__dirname, 'custom.css'));
Save and Ctrl+R your Franz slack windows
@sbealer
sbealer / example.py
Created March 13, 2018 21:45
Ship a compressed (gzip) csv to S3. Write to your compressed file with csv writer in one step. Python 3
import io
import gzip
import csv
import boto3
import os
destination_bucket = 'your-directory'
destination_directory = 'your/directory/'
destination_filename = 'text.csv.gz'
@sbealer
sbealer / examples.sql
Created September 22, 2017 22:38
New & Notable SQL Server 2016 enhancements!
JSON stuff: https://gist.github.com/sbealer/c2d4585570d9334861115c50208fb637
Quick if exists drops!
drop table if exists dw.this_table_doesnt_exist;
Create or Alter!
create or alter view test_view AS
select 'testing new create or alter syntax' as val;
@sbealer
sbealer / sql_server_json_example.sql
Last active September 22, 2017 22:29
Use JSON in Sql Server 2016
declare @json varchar(2000) = '{
"colors": [
{
"color": "black",
"category": "hue",
"type": "primary",
"code": {
"rgba": [255,255,255,1],
"hex": "#000"
}
@sbealer
sbealer / import csv into SQL Server no format file.sql
Last active May 18, 2017 21:48
Import csv into SQL Server without need of format file
INSERT INTO [YOURLINKEDSERVER].[YOURDB].[DBO].YOURTABLE
SELECT
*
,cast('2017-05-20' as date)
FROM OPENROWSET('MSDASQL'
, 'Driver={Microsoft Access Text Driver (*.txt, *.csv)};
DBQ=C:\first_directory\second_directory\'
, 'select * from "your_file.csv"')
@sbealer
sbealer / FIRST_VALUE vs. LAST_VALUE...WHICH ONE DO I USE?!?
Last active June 29, 2017 17:20
first_value_vs_last_value_example
/*Just use FIRST_VALUE. LAST_VALUE takes more coding (in SQL Server) to get the same thing done, such as the inclusion of a ROWS BETWEEN clause:
(Please note that this article applies to SQL Server. Redshift requires you to have a window function regardless of which method you use)
The below query tries to get the 'most recent' value without having to join back on itself.
Two methods, last_value and first_value are used in the attempt:
*/
WITH DATES_EXAMPLE
AS
@sbealer
sbealer / redshift_dim_time.sql
Created November 1, 2016 20:43
Redshift Time Dimension SQL
CREATE VIEW dw.dim_time_vw AS
with nums AS (
SELECT TOP 86400
row_number() over (
PARTITION BY NULL ORDER BY id) AS num
FROM l_browser)
SELECT
to_char(
DATEADD(second, num-1, cast('2000-01-01' AS date)), 'HH24MISS') AS time_key,
@sbealer
sbealer / redshift_dim_date.sql
Last active November 11, 2022 20:32
Redshift Date Dimension SQL
create
--drop
view dw.dim_date_vw as
WITH nums AS (
SELECT TOP 15000 row_number() over (
PARTITION BY NULL order by id) n
FROM l_browser -- or some other large table;
)
@sbealer
sbealer / python_multiprocessing_example.py
Last active December 12, 2022 22:48
Python Multiprocessing/Parallel/Multi Example
import os
import multiprocessing
import random
import time
from services import logger
LOG = logger.get_logger(os.path.basename(__file__))
proc_name = 'Parallel Processing Example using multiprocessing module'