Skip to content

Instantly share code, notes, and snippets.

View morecchia's full-sized avatar

Michael morecchia

View GitHub Profile
@morecchia
morecchia / EfRelationships.cs
Created February 12, 2016 20:11
Set up an Entity Framework database with one-to-many relationships using Code First
using MyProject.Models;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace MyProject.Database
{
public class ArchiveDatabase : DbContext
{
// add a connection string in Web.config
// <add name="MyConnection" connectionString="Server=localhost;Database=MyDatabase;Trusted_Connection=true;" providerName="System.Data.SQLClient" />
@morecchia
morecchia / EfRepository.cs
Created February 12, 2016 20:04
A generic Entity Framework Repository
using System;
using System.Data.Entity;
using System.Linq;
namespace MyProject.Repositories
{
public class EfRepository<T> : IRepository<T>
where T : class
{
protected DbContext Context;
@morecchia
morecchia / EfConnectExistingTable.cs
Last active March 16, 2016 19:33
Use Entity Framework Code First to connect to a table in an existing database
using System.Data.Entity;
using MyProject.Models;
namespace MyProject.Database
{
public class MyDatabase : DbContext
{
// add a connection string in Web.config
// <add name="MyConnection" connectionString="Server=localhost;Database=MyDatabase;Trusted_Connection=true;" providerName="System.Data.SQLClient" />
public MyDatabase() : base("MyConnection") { }
@morecchia
morecchia / discogs-oauth.php
Last active June 5, 2018 00:33
Example OAuth access to the Discogs API
<?php
// This example uses a fork of the OAuthSimple library for PHP
// found here: https://github.com/tonefolder/oauthsimple/tree/master/php
//
// For more information about the OAuth process for applications
// accessing Discogs API, read:
// http://www.discogs.com/developers
require 'oauth.php';
$oauthObject = new OAuthSimple();
$scope = 'http://api.discogs.com';
@morecchia
morecchia / discogs.php
Last active August 29, 2015 13:57
cUrl script to get discogs api data
<?php
$url = "http://api.discogs.com/"; // add the resource info to the url. Ex. releases/1
//initialize the session
$ch = curl_init();
//Set the User-Agent Identifier
curl_setopt($ch, CURLOPT_USERAGENT, 'YOUR_APP_NAME_HERE/0.1 +http://your-site-here.com');