Skip to content

Instantly share code, notes, and snippets.

View csdear's full-sized avatar

Stuart Dear csdear

  • EBSCO
  • Birmingham AL
View GitHub Profile
@csdear
csdear / sqlWildCard_LIKE_.sql
Created May 16, 2014 13:40
SQL LIKE Pattern and Wildcards A. Table Reference B. Where COLUMN NAME C. LIKE '20%' . Percent sign is the wildcard. E.g., '%20', '20%', '%camry% D. OR column name. If you want to search for the pattern in additional columns.
***
SELECT * FROM seo_templates
WHERE main_copy LIKE '20%'
OR page_title LIKE '20%'
***
@csdear
csdear / Update and or Replace.sql
Last active March 17, 2016 19:22
SQL UPDATE / Replace 1. simple update of values #2. Wildcard to replace LIKE values #3. Dealing with the common datatype 'ntext' error #4 Simple Update and replace. Find the oldstring, insert this new string... # 5. Clone values of column x to column y 6. Gotcha multiple updates you dummy
--Updating values - simple
-- SET is the column name(s), and the new values
-- Include where statement to target a specific row
--1. simple update of values
Update dbo.dealers
SET latitude='34.000854', longitude='-81.099379'
WHERE dealer_code = '39054'
***
@csdear
csdear / Try Catch Basic
Created October 7, 2014 14:13
Try / Catch Basic : A try block with a StreamReader statement that opens a data file called data.txt and writes a string from the file. Following the try block is a catch block that catches any exception that results from the try block.
// This will throw a 'System.IO.FileNotFoundException'
public class ProcessFile
{
public static void Main()
{
try
{
StreamReader sr = File.OpenText("data.txt");
Console.WriteLine("The first line of this file is {0}", sr.ReadLine());
sr.Close();
@csdear
csdear / CSV to List - Console
Last active August 29, 2015 14:07
.CSV to List Collection using StreamReader. Simple console demo, outputs contents of list to the console. e.g., 1 on the subject of StreamReader to List
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace CONSOLE
{
class MainLoader
{
@csdear
csdear / HTTP : Get HTTP StatusCode Response Description
Created October 29, 2014 15:17
HTTP : Get HTTP StatusCode Response Description. Params : HTTP url string Method returns the the HTTP StatusCode Description e.g. 'OK'
public String GetHttpResponse(string url)
{
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create("http://" + url);
//webRequest.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse) webRequest.GetResponse();
response.Close();
return response.StatusCode.ToString();
}
@csdear
csdear / Preserve Leading Zeroes.sql
Created November 3, 2014 19:56
Preserve leading zeroes when copy and pasting SQL to Excel
--wrap the column name with this...
SELECT '="' + dealer_code + '"', dealer_name
FROM dealers
@csdear
csdear / jQuery : Injecting Content.css
Created November 11, 2014 21:22
jQuery : Injecting Content
p {
color: blue;
margin: 8px;
}
b {
color: red;
}
@csdear
csdear / If Else Shorthand Javascript.js
Created November 18, 2014 16:44
If Else Shorthand Javascript
var modelSeries = $('#seriesName').text();
var gradeLevel = $('#gradeLevel').text();
function seriesFormatter (series, grade) {
var result = (series.indexOf(grade.toLowerCase()) >= 0) ? series : series + " " + grade;
return result;
}
var str = seriesFormatter(modelSeries, gradeLevel);
@csdear
csdear / Transaction - COMMIT & ROLL BACK.sql
Last active August 29, 2015 14:11
Transaction - COMMIT & ROLL BACK A safe guard against mistakes, best practice is to alway wrap changes that are going to affect the table in these transactional code snippets.
--1. BEGIN transaction, write your query and execute.
SELECT *
FROM [stuart_sandbox].[dbo].[Categories]
BEGIN transaction
UPDATE [stuart_sandbox].[dbo].[Categories]
SET Description ='Sushi'
WHERE CategoryID = '8'
--2. Check the results of your query
@csdear
csdear / Create Javascript Object - new Notation and Constructor Functions.js
Created December 30, 2014 13:47
Create Javascript Object : new Notation and Constructor Functions • constructor function will be used as the blueprint when creating new instances with the new kw • Constructor function special b/c you can refer to an instance by using the this keyword. • Convention to use uppercase at the beginning of a constructor function -- e.g., Car. • Ea i…
function Car(type) {
this.speed = 0;
this.type = type || "No type";
this.drive = function(newSpeed) {
this.speed = newSpeed;
}
}
//creating a new instance of the Car object, the bmw.
var bmw =new Car("BMW");