Skip to content

Instantly share code, notes, and snippets.

View clintmjohnson's full-sized avatar

Clint Johnson clintmjohnson

View GitHub Profile
@clintmjohnson
clintmjohnson / SendemailwGmail.py
Last active August 29, 2015 14:17
This Python code sends a text email using Gmail account,
import smtplib
fromaddr = 'email@gmail.com'
toaddrs = 'email@gmail.com'
msg = 'There was a terrible error that occured and I wanted you to know!'
# Credentials (if needed)
username = 'email@gmail.com'
password = ''
@clintmjohnson
clintmjohnson / bubblestest.py
Created April 13, 2015 23:17
This is a Text Bubbles Script pulling data from a URL and Pretty Printing it.
import bubbles
URL = "https://raw.github.com/Stiivi/cubes/master/examples/hello_world/data.csv"
p = bubbles.Pipeline()
p.source(bubbles.data_object("csv_source", URL, infer_fields=True))
p.aggregate("Category", "Amount (US$, Millions)")
p.pretty_print()
@clintmjohnson
clintmjohnson / formatphonenumber
Last active August 29, 2015 14:20
This SQL Query converts a Phone Number Like this '1234567891' into this '123-456-7891'
SELECT
SUBSTRING([Customer Phone], 1, 3) + '-' + SUBSTRING([Customer Phone], 4, 3) + '-' +SUBSTRING([Customer Phone], 7, 4)
FROM tablename
@clintmjohnson
clintmjohnson / MMDDYYYYto
Created May 14, 2015 21:20
Usage #3 : Format Date from MMDDYYYY to MM/DD/YYYY
DECLARE @MMDDYYYY VARCHAR(10)
SET @MMDDYYYY = '07042013'
SELECT STUFF(STUFF(@MMDDYYYY, 3, 0, '/'), 6, 0, '/') AS [MM/DD/YYYY]
@clintmjohnson
clintmjohnson / vertical2comma.SQL
Last active August 29, 2015 14:21
Convert Vertical Row value to Comma Separated Values Using STUFF SQL SERVER
DECLARE @Heroes TABLE (
[HeroName] VARCHAR(20)
)
INSERT INTO @Heroes ( [HeroName] )
VALUES ( 'Superman' ), ( 'Batman' ), ('Ironman'), ('Wolverine')
--SELECT * FROM @Heroes
SELECT STUFF((SELECT ',' + [HeroName]
FROM @Heroes
@clintmjohnson
clintmjohnson / ExtractTextfrom2Strings.SQL
Last active August 29, 2015 14:21
This SQL Server Query Extracts Text between two Specific Text Values using CHARINDEX.SUBSTRING
substring( LEFT([Product Details], charindex('Product Name', [Product Details], CHARINDEX('SKU: ', [Product Details]))-3), CHARINDEX('SKU: ', [Product Details]) + len('SKU: '), LEN([Product Details]))
@clintmjohnson
clintmjohnson / REPLACEPhone.SQL
Last active August 29, 2015 14:21
This is a Nested REPLACE Query for Stripping non numerical values from Phone Numbers.
,REPLACE(
REPLACE(
REPLACE(
REPLACE(
REPLACE([Billing Phone],'(','')
,')','')
,'-','')
,' ','')
,'+','') AS PhoneNumber
@clintmjohnson
clintmjohnson / RemoveLeft2SQL.SQL
Last active August 29, 2015 14:21
This Select Query removes the first 2 Characters from the left of a String
,RIGHT(columnname, LEN(columnname) - 2) AS MyTrimmedColumn
@clintmjohnson
clintmjohnson / VerifyIfUPC.SQL
Last active October 13, 2015 17:32
This CASE Statement checks to see if a string is a Valid UPC Number or Not. - It verifies that the string has only Numbers, and its length is 12
USE DatabaseNameHere
SELECT
-- This CASE Expression Verifies that the Value in the UPC Field is All Numbers and It's Total Length is 12
,CASE WHEN ISNUMERIC(UPC) = 1 AND LEN([UPC]) = 12 THEN [UPC]
WHEN ISNUMERIC(UPC) = 1 AND LEN([UPC]) = 11 THEN '0'+[UPC]
ELSE '' END AS [UPC]
FROM dbo.YourTableNameHere
@clintmjohnson
clintmjohnson / channeladvisorordersapi.py
Created May 18, 2015 17:40
Channel Advisor / Python Get Orders API Script
from suds.client import Client
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
# Specify Login Information
developer_key = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
password = 'xxxxxxxx'
account_guid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'