Skip to content

Instantly share code, notes, and snippets.

View clintmjohnson's full-sized avatar

Clint Johnson clintmjohnson

View GitHub Profile
@clintmjohnson
clintmjohnson / LnS_Product_Query.sql
Last active December 13, 2016 23:43
Land n Sea - eBay / Magento SQL Server Query
USE companydb
DECLARE @companyname_active TABLE
(
[Custom Label] VARCHAR(75)
,[Purchases] INT
,[Category Number] INT
,[Price] DECIMAL(6,2)
,[Item Title] VARCHAR(90)
)
@clintmjohnson
clintmjohnson / findItemsIneBayStores.py
Last active February 14, 2017 02:39
Find Items in eBay Stores.
# encoding=utf8 # This eliminates issues with Unicode errors that I was previously encountering.
import sys
reload(sys)
sys.setdefaultencoding('utf8')
from ebaysdk.finding import Connection as Finding
import csv
"""The first function only finds a total page count. This func outputs the Page count,
and will be used as Range in the next Func."""
@clintmjohnson
clintmjohnson / dotoeachvalueinlist.py
Created September 16, 2015 23:21
Do something to every item in a list function - python
n = [3, 5, 7]
def double_list(x):
for i in range(0, len(x)):
x[i] = x[i] * 2
return x
print double_list(n)
@clintmjohnson
clintmjohnson / nimbletext_replace
Created September 6, 2015 20:57
this line of code replaces text in each line for nimbletext - http://nimbletext.com/HowTo/ManipulateText
<% $row
.replace(/a dull boy/,'an axe-wielding maniac')
.replace(/an axe/,'a teddy bear')
.replace(/work/,'sex')
%>
@clintmjohnson
clintmjohnson / nimbletext_insert
Last active September 6, 2015 20:02
Use nimbletext to create SQL Insert query - http://nimbletext.com/HowTo/GenerateInsert
$ONCE
Insert into Contacts (FirstName, LastName, Company)
Values
$EACH+
('$0', '$1', '$2')<% if ($rownumOne != $numrows) {','} %>
#!/usr/bin/python
import imaplib
import csv
from email import message_from_string
import time
srv = imaplib.IMAP4_SSL("imap.gmail.com")
srv.login('[email protected]', 'joepw')
srv.select('[Gmail]/Drafts')
@clintmjohnson
clintmjohnson / CASE_SUB_QUERIES.sql
Last active August 29, 2015 14:23
SQL Server Searched CASE With Sub Queries Very Powerful
SELECT au_lname, au_fname, title, Category =
CASE
WHEN (SELECT AVG(royaltyper) FROM titleauthor ta
WHERE t.title_id = ta.title_id) > 65
THEN 'Very High'
WHEN (SELECT AVG(royaltyper) FROM titleauthor ta
WHERE t.title_id = ta.title_id)
BETWEEN 55 and 64
THEN 'High'
WHEN (SELECT AVG(royaltyper) FROM titleauthor ta
@clintmjohnson
clintmjohnson / Merge_From_File.txt
Last active August 29, 2015 14:23
SQL Server Merge From File Such as CSV Using OPENROWSET
SELECT *
FROM OPENROWSET(BULK 'c:\temp\Customers.txt',
FORMATFILE = 'c:\temp\CustomersFmt.xml') AS SRC;
SELECT *
FROM OPENROWSET(BULK 'c:\temp\Customers.txt',
FORMATFILE = 'c:\temp\CustomersFmt.xml') AS SRC;
Similarly, the OPENROWSET function can be used directly in the USING clause of the MERGE statement, like so:
MERGE INTO Sales.MyCustomers AS TGT
USING OPENROWSET(BULK 'c:\temp\Customers.txt',
FORMATFILE = 'c:\temp\CustomersFmt.xml') AS SRC
@clintmjohnson
clintmjohnson / DeleteonebyOne.sql
Created June 14, 2015 13:57
Delete Duplicate Key Id Values on a SQL Server Table One by One
USE TableName
MERGE TOP (1) Product_Master_Table AS a
USING
(SELECT model_number,COUNT(*) AS dupeCount
FROM Product_Staging_Table
WHERE model_number <> '' AND model_number IS NOT NULL
GROUP BY model_number
HAVING COUNT(*) > 1) AS b