Life is like Code, you never know what you will create next

Get Parameter From Url with Javascript

23. October 2013 08:11 by Scott in javascript  //  Tags:   //   Comments (0)
function getParameterByName(name){
var match = (RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

TimeZone Import List for MSSql

4. October 2013 17:52 by Scott in MSSql, TSql  //  Tags:   //   Comments (0)

Placed here for reference.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TimeZone](
    [ZoneId] [int] IDENTITY(1,1) NOT NULL,
    [Location] [nvarchar](max) NULL,
    [GMT] [nvarchar](max) NULL,
    [GMTOffset] [int] NOT NULL,
    [Created] [datetime] NOT NULL,
    [LastModified] [datetime] NULL,
 CONSTRAINT [PK_TimeZone] PRIMARY KEY CLUSTERED 
(
    [ZoneId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

 

INSERT INTO TimeZone VALUES 
( 'International Date Line West', '(GMT-12:00)', -12,'10-4-2013', '10-4-2013'),
( 'Midway Island', '(GMT-11:00)', -11,'10-4-2013', '10-4-2013'),
( 'Samoa', '(GMT-11:00)', -11,'10-4-2013', '10-4-2013'),
( 'Hawaii', '(GMT-10:00)', -10,'10-4-2013', '10-4-2013'),
( 'Alaska', '(GMT-09:00)', -9,'10-4-2013', '10-4-2013'),
( 'Pacific Time (US & Canada)', '(GMT-08:00)', -8,'10-4-2013', '10-4-2013'),
( 'Tijuana', '(GMT-08:00)', -8,'10-4-2013', '10-4-2013'),
( 'Arizona', '(GMT-07:00)', -7,'10-4-2013', '10-4-2013'),
( 'Mountain Time (US & Canada)', '(GMT-07:00)', -7,'10-4-2013', '10-4-2013'),
( 'Chihuahua', '(GMT-07:00)', -7,'10-4-2013', '10-4-2013'),
( 'La Paz', '(GMT-07:00)', -7,'10-4-2013', '10-4-2013'),
( 'Mazatlan', '(GMT-07:00)', -7,'10-4-2013', '10-4-2013'),
( 'Central Time (US & Canada)', '(GMT-06:00)', -6,'10-4-2013', '10-4-2013'),
( 'Central America', '(GMT-06:00)', -6,'10-4-2013', '10-4-2013'),
( 'Guadalajara', '(GMT-06:00)', -6,'10-4-2013', '10-4-2013'),
( 'Mexico City', '(GMT-06:00)', -6,'10-4-2013', '10-4-2013'),
( 'Monterrey', '(GMT-06:00)', -6,'10-4-2013', '10-4-2013'),
( 'Saskatchewan', '(GMT-06:00)', -6,'10-4-2013', '10-4-2013'),
( 'Eastern Time (US & Canada)', '(GMT-05:00)', -5,'10-4-2013', '10-4-2013'),
( 'Indiana (East)', '(GMT-05:00)', -5,'10-4-2013', '10-4-2013'),
( 'Bogota', '(GMT-05:00)', -5,'10-4-2013', '10-4-2013'),
( 'Lima', '(GMT-05:00)', -5,'10-4-2013', '10-4-2013'),
( 'Quito', '(GMT-05:00)', -5,'10-4-2013', '10-4-2013'),
( 'Atlantic Time (Canada)', '(GMT-04:00)', -4,'10-4-2013', '10-4-2013'),
( 'Caracas', '(GMT-04:00)', -4,'10-4-2013', '10-4-2013'),
( 'La Paz', '(GMT-04:00)', -4,'10-4-2013', '10-4-2013'),
( 'Santiago', '(GMT-04:00)', -4,'10-4-2013', '10-4-2013'),
( 'Newfoundland', '(GMT-03:30)', -3,'10-4-2013', '10-4-2013'),
( 'Brasilia', '(GMT-03:00)', -3,'10-4-2013', '10-4-2013'),
( 'Buenos Aires', '(GMT-03:00)', -3,'10-4-2013', '10-4-2013'),
( 'Georgetown', '(GMT-03:00)', -3,'10-4-2013', '10-4-2013'),
( 'Greenland', '(GMT-03:00)', -3,'10-4-2013', '10-4-2013'),
( 'Mid-Atlantic', '(GMT-02:00)', -2,'10-4-2013', '10-4-2013'),
( 'Azores', '(GMT-01:00)', -1,'10-4-2013', '10-4-2013'),
( 'Cape Verde Is.', '(GMT-01:00)', -1,'10-4-2013', '10-4-2013'),
( 'Casablanca', '(GMT)', 0,'10-4-2013', '10-4-2013'),
( 'Dublin', '(GMT)', 0,'10-4-2013', '10-4-2013'),
( 'Edinburgh', '(GMT)', 0,'10-4-2013', '10-4-2013'),
( 'Lisbon', '(GMT)', 0,'10-4-2013', '10-4-2013'),
( 'London', '(GMT)', 0,'10-4-2013', '10-4-2013'),
( 'Monrovia', '(GMT)', 0,'10-4-2013', '10-4-2013'),
( 'Amsterdam', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Belgrade', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Berlin', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Bern', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Bratislava', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Brussels', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Budapest', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Copenhagen', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Ljubljana', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Madrid', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Paris', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Prague', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Rome', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Sarajevo', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Skopje', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Stockholm', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Vienna', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Warsaw', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'West Central Africa', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Zagreb', '(GMT+01:00)', 1,'10-4-2013', '10-4-2013'),
( 'Athens', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Bucharest', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Cairo', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Harare', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Helsinki', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Istanbul', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Jerusalem', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Kyev', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Minsk', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Pretoria', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Riga', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Sofia', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Tallinn', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Vilnius', '(GMT+02:00)', 2,'10-4-2013', '10-4-2013'),
( 'Baghdad', '(GMT+03:00)', 3,'10-4-2013', '10-4-2013'),
( 'Kuwait', '(GMT+03:00)', 3,'10-4-2013', '10-4-2013'),
( 'Moscow', '(GMT+03:00)', 3,'10-4-2013', '10-4-2013'),
( 'Nairobi', '(GMT+03:00)', 3,'10-4-2013', '10-4-2013'),
( 'Riyadh', '(GMT+03:00)', 3,'10-4-2013', '10-4-2013'),
( 'St. Petersburg', '(GMT+03:00)', 3,'10-4-2013', '10-4-2013'),
( 'Volgograd', '(GMT+03:00)', 3,'10-4-2013', '10-4-2013'),
( 'Tehran', '(GMT+03:30)', 3,'10-4-2013', '10-4-2013'),
( 'Abu Dhabi', '(GMT+04:00)', 4,'10-4-2013', '10-4-2013'),
( 'Baku', '(GMT+04:00)', 4,'10-4-2013', '10-4-2013'),
( 'Muscat', '(GMT+04:00)', 4,'10-4-2013', '10-4-2013'),
( 'Tbilisi', '(GMT+04:00)', 4,'10-4-2013', '10-4-2013'),
( 'Yerevan', '(GMT+04:00)', 4,'10-4-2013', '10-4-2013'),
( 'Kabul', '(GMT+04:30)', 4,'10-4-2013', '10-4-2013'),
( 'Ekaterinburg', '(GMT+05:00)', 5,'10-4-2013', '10-4-2013'),
( 'Islamabad', '(GMT+05:00)', 5,'10-4-2013', '10-4-2013'),
( 'Karachi', '(GMT+05:00)', 5,'10-4-2013', '10-4-2013'),
( 'Tashkent', '(GMT+05:00)', 5,'10-4-2013', '10-4-2013'),
( 'Chennai', '(GMT+05:30)', 5,'10-4-2013', '10-4-2013'),
( 'Kolkata', '(GMT+05:30)', 5,'10-4-2013', '10-4-2013'),
( 'Mumbai', '(GMT+05:30)', 5,'10-4-2013', '10-4-2013'),
( 'New Delhi', '(GMT+05:30)', 5,'10-4-2013', '10-4-2013'),
( 'Kathmandu', '(GMT+05:45)', 5,'10-4-2013', '10-4-2013'),
( 'Almaty', '(GMT+06:00)', 6,'10-4-2013', '10-4-2013'),
( 'Astana', '(GMT+06:00)', 6,'10-4-2013', '10-4-2013'),
( 'Dhaka', '(GMT+06:00)', 6,'10-4-2013', '10-4-2013'),
( 'Novosibirsk', '(GMT+06:00)', 6,'10-4-2013', '10-4-2013'),
( 'Sri Jayawardenepura', '(GMT+06:00)', 6,'10-4-2013', '10-4-2013'),
( 'Rangoon', '(GMT+06:30)', 6,'10-4-2013', '10-4-2013'),
( 'Bangkok', '(GMT+07:00)', 7,'10-4-2013', '10-4-2013'),
( 'Hanoi', '(GMT+07:00)', 7,'10-4-2013', '10-4-2013'),
( 'Jakarta', '(GMT+07:00)', 7,'10-4-2013', '10-4-2013'),
( 'Krasnoyarsk', '(GMT+07:00)', 7,'10-4-2013', '10-4-2013'),
( 'Beijing', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Chongqing', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Hong Kong', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Irkutsk', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Kuala Lumpur', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Perth', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Singapore', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Taipei', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Ulaan Bataar', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Urumqi', '(GMT+08:00)', 8,'10-4-2013', '10-4-2013'),
( 'Osaka', '(GMT+09:00)', 9,'10-4-2013', '10-4-2013'),
( 'Sapporo', '(GMT+09:00)', 9,'10-4-2013', '10-4-2013'),
( 'Seoul', '(GMT+09:00)', 9,'10-4-2013', '10-4-2013'),
( 'Tokyo', '(GMT+09:00)', 9,'10-4-2013', '10-4-2013'),
( 'Yakutsk', '(GMT+09:00)', 9,'10-4-2013', '10-4-2013'),
( 'Adelaide', '(GMT+09:30)', 9,'10-4-2013', '10-4-2013'),
( 'Darwin', '(GMT+09:30)', 9,'10-4-2013', '10-4-2013'),
( 'Brisbane', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Canberra', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Guam', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Hobart', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Melbourne', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Port Moresby', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Sydney', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Vladivostok', '(GMT+10:00)', 10,'10-4-2013', '10-4-2013'),
( 'Magadan', '(GMT+11:00)', 11,'10-4-2013', '10-4-2013'),
( 'New Caledonia', '(GMT+11:00)', 11,'10-4-2013', '10-4-2013'),
( 'Solomon Is.', '(GMT+11:00)', 11,'10-4-2013', '10-4-2013'),
( 'Auckland', '(GMT+12:00)', 12,'10-4-2013', '10-4-2013'),
( 'Fiji', '(GMT+12:00)', 12,'10-4-2013', '10-4-2013'),
( 'Kamchatka', '(GMT+12:00)', 12,'10-4-2013', '10-4-2013'),
( 'Marshall Is.', '(GMT+12:00)', 12,'10-4-2013', '10-4-2013'),
( 'Wellington', '(GMT+12:00)', 12,'10-4-2013', '10-4-2013'),
( 'Nuku''alofa', '(GMT+13:00)', 13,'10-4-2013', '10-4-2013');

Getting Attacked by 207.210.85.102

1. October 2013 11:17 by Scott in   //  Tags:   //   Comments (0)

My small software startup is being attacked right now by 207.210.85.102 using SQL Injection.  We run a small ecommerce site along with a very large Sports Portal.  They are using attacks within our variables such as

?category=31111111111111"+UNION+SELECT+CHAR(45,120,49,45,81,45),CHAR(45,120,50,45,81,45),CHAR(45,120,51,45,81,45),CHAR(45,120,52,45,81,45),CHAR(45,120,53,45,81,45),CHAR(45,120,54,45,81,45),CHAR(45,120,55,45,81,45),CHAR(45,120,56,45,81,45),CHAR(45,120,57,45,81,45)+--+/*+order+by+"as+/*

?category=31111111111111'+UNION+SELECT+CHAR(45,120,49,45,81,45),CHAR(45,120,50,45,81,45),CHAR(45,120,51,45,81,45),CHAR(45,120,52,45,81,45),CHAR(45,120,53,45,81,45),CHAR(45,120,54,45,81,45),CHAR(45,120,55,45,81,45),CHAR(45,120,56,45,81,45),CHAR(45,120,57,45,81,45),CHAR(45,120,49,48,45,81,45),CHAR(45,120,49,49,45,81,45),CHAR(45,120,49,50,45,81,45),CHAR(45,120,49,51,45,81,45),CHAR(45,120,49,52,45,81,45),CHAR(45,120,49,53,45,81,45),CHAR(45,120,49,54,45,81,45),CHAR(45,120,49,55,45,81,45),CHAR(45,120,49,56,45,81,45),CHAR(45,120,49,57,45,81,45),CHAR(45,120,50,48,45,81,45),CHAR(45,120,50,49,45,81,45),CHAR(45,120,50,50,45,81,45),CHAR(45,120,50,51,45,81,45),CHAR(45,120,50,52,45,81,45)+--+/*+order+by+'as+/*

Small Google Calendar Class To Add Events

17. September 2013 18:22 by Scott in C#  //  Tags:   //   Comments (0)

I created a small C# class to add Google calendar events to a calendar in C#.  It is quite simple, but I didn’t find it searching the internet, so here it is.  Its dead simple.

 public class GoogleCalendar
    {

        private static string GoogleUrl = "http://www.google.com/calendar/event?action=TEMPLATE";
        public string What { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public string Description { get; set; }
        public string Location { get; set; }
        public string WebsiteName { get; set; }
        public string Website { get; set; }

        public string GetGoogleUrl()
        {
            //20130918T103000Z
            return GoogleUrl + "&text=" + What + "&dates=" + StartDate.ToString("yyyyMMddTHHmmssZ") + "/" + EndDate.ToString("yyyyMMddTHHmmssZ") + "&details=" + Description + "&location=" + Location + "&trp=false" + "&sprop=" + WebsiteName + "&sprop=name:" + Website;
        }
    }

Convert Meters To Miles C#

11. September 2013 06:31 by scott in   //  Tags:   //   Comments (0)

 

 public static double ConvertMetersToMiles(double meters)
    {
        return (meters / 1609.344);
    }

So there I was, Searching for an obscure Email Address...

29. August 2013 14:05 by Scott in Facebook  //  Tags:   //   Comments (0)

So there I was searching for an obscure email address....

And there I found a CRAZY Facebook URL....

https://www.wwww.wwww.wwww.wwww.wwww.0.facebook.com/rdnation

What is that you say?  Well I have NO idea.  

Why not you tell me?  Why does Facebook need soo many subdomains?

Put Code in Head Tags of HTML with Webforms

22. August 2013 07:29 by scott in   //  Tags:   //   Comments (0)

Working on a project and I have to put version numbers for CSS and Javascript files using the OLD webforms for ASP.NET.  Since I am working with such an old framework, I need to be creative.

Here is how to do it.

   1:    <head runat="server">
   2:  <asp:PlaceHolder runat="server">
   3:            <%=  @"<link rel='stylesheet' type='text/css'  href='/css/main.css?v=" + Web.Configuration.JS_VERSION + "' />" %>
   4:            <%=  @"<script type='text/javascript' src='/scripts/default.js?v=" + Web.Configuration.JS_VERSION + "'></script>" %>
   5:        </asp:PlaceHolder>
   6:  </head>

Interview Questions

16. April 2013 12:35 by Scott in   //  Tags:   //   Comments (0)

I am starting to go on Interviews.  I was asked some questions I needed a mental refresher on.  I guess I don’t use these on a day to day basis with my current company, so I fell out of habit with them.  I also think that since I didn’t receive any formal training in CS, I don’t know much for keywords which could also be the problem.  I understand the concepts, just not the actual verbs for each concept.

1. What is a primitive data type?

Char, Int, Floating Points, boolean and pointers would all be considered primitive data types.

2. Whats relationship between objects and classes?

Objects are the actual instance of each class.  Objects can be created and destroyed, objects are living.

3. Whats an Interface?

A template of a class that needs to be implemented or inherited from, but without doing any work.

4. Whats an Abstract Class?

Same as an interface, but this class can do work within its methods.

5. Whats a static variable?

A variable that lives within the class, but it’s the same for every object of that class.  So if it changes for one object, it will change for every object.

6. Whats a Race condition?

Where an output of “mostly” multi threaded programming is dependent upon the timing of the uncontrolled events.

7. What is a deadlock?

Where two competing actions are waiting for the other to finish.

Quote of the Day

28. December 2012 17:12 by Scott in Quote  //  Tags:   //   Comments (0)

Good Coders Code, Great Coders Reuse

Give It To the Lazy Person

9. May 2012 20:04 by Scott in   //  Tags:   //   Comments (0)

If you have a difficult task to do, give it to a lazy man, he will find an easier way to do it.

 

A toothpaste factory had a problem: they sometimes shipped empty boxes, without the tube inside. This was due to the way the production line was set up, and people with experience in designing production lines will tell you how difficult it is to have everything happen with timings so precise that every single unit coming out of it is perfect 100% of the time. Small variations in the environment (which can’t be controlled in a cost-effective fashion) mean you must have quality assurance checks smartly distributed across the line so that customers all the way down the supermarket don’t get pissed off and buy someone else’s product instead.

Understanding how important that was, the CEO of the toothpaste factory got the top people in the company together and they decided to start a new project, in which they would hire an external engineering company to solve their empty boxes problem, as their engineering department was already too stretched to take on any extra effort. The project followed the usual process: budget and project sponsor allocated, RFP, third-parties selected, and six months (and $8 million) later they had a fantastic solution — on time, on budget, high quality and everyone in the project had a great time. They solved the problem by using some high-tech precision scales that would sound a bell and flash lights whenever a toothpaste box weighing less than it should. The line would stop, and someone had to walk over and yank the defective box out of it, pressing another button when done.

A while later, the CEO decides to have a look at the ROI of the project: amazing results! No empty boxes ever shipped out of the factory after the scales were put in place. Very few customer complaints, and they were gaining market share. “That’s some money well spent!” – he says, before looking closely at the other statistics in the report.

It turns out, the number of defects picked up by the scales was 0 after three weeks of production use. It should’ve been picking up at least a dozen a day, so maybe there was something wrong with the report. He filed a bug against it, and after some investigation, the engineers come back saying the report was actually correct. The scales really weren'’t picking up any defects, because all boxes that got to that point in the conveyor belt were good.

Puzzled, the CEO travels down to the factory, and walks up to the part of the line where the precision scales were installed. A few feet before it, there was a $20 desk fan, blowing the empty boxes out of the belt and into a bin. “Oh, that — one of the guys put it there ’cause he was tired of walking over every time the bell rang”, says one of the workers.