t-sql

Create a table that contains one one, two twos, three threes etc. upto a given maximum using t-SQl

DECLARE @max int
declare @val int
declare @inner int
set @val = 0
SET @max = 20

WHILE   @val<=@max BEGIN
	set @inner=0
		WHILE   @inner<@val BEGIN
				insert into @id(number) values (@val)
				set @inner= @inner+1
			END
		set @val = @val +1
	END

select * from @id
select count(*) from @id



Razor and c# etc.

Notes on my first stab at MVC on vs2010

@ are very important.

A good quick reference for those confused about the cshtml syntax:
http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/

Call a function from the page:

@( projectname.Controllers.SpecificController.FuntionName())

Basically fully qualify the name of the function and you should be fine.
You might have to declare the function as static.

http://www.w3schools.com/aspnet/showfile_c.asp?filename=try_webpages_cs_003

Help my VS2010 doesn’t work properly for the model section!!
“DBContext” Are you missing an assembly reference?

http://www.microsoft.com/en-gb/download/confirmation.aspx?id=1491 and include

using System.Data.Entity;

at the top of your source file/class whatever…

Simple Java Insertion Sort

package insertionshort;
public class InsertionShort {
    public static void main(String[] args) {
        int[] a = {123, 235, 23, 46, 34, 2, 45, 235, 25, 65, 46, 2345, 25, 246, 24, 5246, 24, 6};
        intInsertionSort(a);
    }
    public static void intInsertionSort(int[] a) 
    {
        for (int i = 0; i < a.length; i++) {
            int temp = a[i];
            int j;
            for (j = i - 1; j >= 0 && temp < a[j]; j--) 
            {
                a[j + 1] = a[j];
            }
            a[j + 1] = temp;
            for (int f = 0; f < a.length; f++) 
            {
                System.out.print(a[f] + "\t");
            }
            System.out.println();
        }
    }
}

GDELT data into ms-sql

Go…here
download the historical backfiles

Use the following script to create a database in the required location:

CREATE TABLE GDELT_HISTORICAL (
 GLOBALEVENTID bigint , --1
 SQLDATE int, 
 MonthYear char(6) , 
 [Year] char(4) , 
 FractionDate decimal , --5
 Actor1Code char(55) , 
 Actor1Name char(255) , 
 Actor1CountryCode char(55) , 
 Actor1KnownGroupCode char(55) , 
 Actor1EthnicCode char(55) , --10
 Actor1Religion1Code char(55) , 
 Actor1Religion2Code char(55) , 
 Actor1Type1Code char(55) , 
 Actor1Type2Code char(55) , 
 Actor1Type3Code char(55) , 
 Actor2Code char(55) , --16
 Actor2Name char(255) , 
 Actor2CountryCode char(55) , 
 Actor2KnownGroupCode char(55) , 
 Actor2EthnicCode char(55) , 
 Actor2Religion1Code char(55) , 
 Actor2Religion2Code char(55) , 
 Actor2Type1Code char(55) , 
 Actor2Type2Code char(55) , 
 Actor2Type3Code char(55) , 
 IsRootEvent int , 
 EventCode char(4) , 
 EventBaseCode char(4) , 
 EventRootCode char(4) , 
 QuadClass int , 
 GoldsteinScale decimal , 
 NumMentions int , 
 NumSources int , 
 NumArticles int , 
 AvgTone decimal , 
 Actor1Geo_Type int  , 
 Actor1Geo_FullName char(255) , 
 Actor1Geo_CountryCode char(2) , 
 Actor1Geo_ADM1Code char(4) , 
 Actor1Geo_Lat float , 
 Actor1Geo_Long float , 
 Actor1Geo_FeatureID int  , 
 Actor2Geo_Type int  , 
 Actor2Geo_FullName char(255) , 
 Actor2Geo_CountryCode char(2) , 
 Actor2Geo_ADM1Code char(4) , 
 Actor2Geo_Lat float , 
 Actor2Geo_Long float , 
 Actor2Geo_FeatureID int  , 
 ActionGeo_Type int  , 
 ActionGeo_FullName char(255) , 
 ActionGeo_CountryCode char(2) , 
 ActionGeo_ADM1Code char(4) , 
 ActionGeo_Lat float , 
 ActionGeo_Long float , 
 ActionGeo_FeatureID float  , 
 DATEADDED int
);

Unzip all your history files into one location and then run this script for each file:

  BULK INSERT GDELT_HISTORICAL
    FROM 'C:\Users\MONKEYMIKE\Desktop\201302.csv'
    WITH
        (
		FIELDTERMINATOR = '\t'
		, ROWTERMINATOR = '0x0a'--'\n'
		 )

Excel: replace a character or string with CR LF

This is a technique aimed at splitting up a long cumbersome string held in a single cell using new line breaks. It requires that we replace a normal character with the special characters [CR][LF].

Why would you want to do this?
Well sometimes it looks nice and it makes life easier, or it can make the data easier to scan through. I first used it to show ICD10 Diagnosis code strings from a concatanated string into a single readable cell.

To start off generate your file so that each part of the string that you want on a seperate line has a unique character (or unique string) at the end of the subsection.
In this example I’ve used “: ”
Pic1
Now highlight the section you want to change. Ctrl + A on a section etc.
Then bring up the find and replace dialog using Ctrl + H
In this example I needed to replace “: ” (thats colon followed by a space)
pic2
Now place your cursor in the replace section:
Hold down ALT + 010 release (the ALT key) and then ALT + 013 then release again.
Press the replace all button and away it goes, It can take longer doing this than a normal find and replace.
pic3
…and that’s what you get newlines instead of “: ”

GIS in R cran

library(maptools)
library(Cairo)
walesCoast<-readShapeSpatial("Z:/MAPPING DATA/Meridian 2 Shape/data/coast_ln_polyline.shp", proj4string=CRS("+init=epsg:27700"))
walesUA<-readShapeSpatial("Z:/MAPPING DATA/Meridian 2 Shape/data/district_region.shp", proj4string=CRS("+init=epsg:27700"))
x1x2<-c(221000,346594)
y1y2<-c(269406,395000)

plot(walesUA,xaxs="i",yaxs="i",xlim=x1x2,ylim=y1y2,lwd=1)
plot(walesCoast,xaxs="i",yaxs="i",xlim=x1x2,ylim=y1y2,lwd=3,col="red", add=TRUE)

mtext("upvar",side=2,line=2,col=1)
mtext("Bottom",side=1,line=2,col=2)
mtext("Top",side=3,line=2,col=3)
mtext("Right",side=4,line=1,col=4)