Skip to content

Instantly share code, notes, and snippets.

View dalmat36's full-sized avatar

Matt Dalesio dalmat36

View GitHub Profile
@dalmat36
dalmat36 / ConnectingToMongoDB
Last active August 29, 2015 14:18
This snippet of code connects to MongoDB running on a local machine and gets the "people" collection from the "mydb" database. (collection is defined as a global variable here)
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
MongoDatabase database = mongoClient.getDatabase("mydb");
collection = database.getCollection("people");
@dalmat36
dalmat36 / JDBCStatementDemo.java
Last active August 29, 2015 14:12
Using JDBC Statements
package main;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import md.java.db.DBConnectionUtils;
import md.java.io.ReadProperties;
@dalmat36
dalmat36 / PropertiesDemo.java
Last active August 29, 2015 14:11
Java-IO-Properties
package com.javademo;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
public class PropertiesDemo {
public static void main(String[] args) {
# An addition
5 + 5
# A subtraction
5 - 5
# A multiplication
3 * 5
# A division
@dalmat36
dalmat36 / simplelog4j
Created June 18, 2014 19:15
Simple Log4j example
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
public class TestLog4j {
static Logger logger = Logger.getLogger("JTST");
public static void main(String[] args) {
// TODO Auto-generated method stub
try
@dalmat36
dalmat36 / Java_LTP_CH8_5_Time2
Last active August 29, 2015 14:01
Class to test Time2 Class
public class Time2 {
private int hour; //0-23
private int minute; //0-59
private int second; //0-59
//set a new time value using universal time; ensure that
//the data remains consistent by setting invalid values to zero
public Time2()
{
this(0, 0, 0);
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>KML Name</name>
<description>KML Description</description>
<Style id="style1">
<LineStyle>
<color>990000ff</color>
<width>4</width>
</LineStyle>
@dalmat36
dalmat36 / Programming SQL-Spatial-1
Last active August 29, 2015 13:58
Spatial Data with SQL Server
DECLARE @line geometry = 'LINESTRING(5 15,22 10)'
select @line AS AsRaw, @line.ToString() AS AsWKT
GO
@dalmat36
dalmat36 / Programming SQL Server 2012 Ch10-1
Last active August 29, 2015 13:58
Using ADO.net to execute SQL queries
//Insert Customer using Direct T-SQL Statement
private void btnDirectSql_Click(object sender, EventArgs e)
{
const string ConnStr =
// "Data Source=localhost;Initial Catalog=SampleDb;Integrated Security=true;";
"Data Source=(localdb)\\Projects;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;Initial Catalog=SampleDb;";
const string TSql =
"INSERT INTO Customer (FirstName, LastName) VALUES ('Lukas', 'Keller')";
@dalmat36
dalmat36 / BCHS-Footer-3
Created March 30, 2014 18:49
Revision #3 of the Blair County Historical Society homepage footer