Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mizrael's full-sized avatar
😼
my cat owns the keyboard.

David Guida mizrael

😼
my cat owns the keyboard.
View GitHub Profile
public class LinkedInController : Controller
{
public RedirectResult Profile()
{
var redirectUrl = "http://mydomain/linkedin/profilereturn/";
var url = GetAuthorizationUrl(redirectUrl);
return Redirect(url.ToString());
}
public ActionResult ProfileReturn(string code, string state)
@mizrael
mizrael / customer_orders.sql
Created February 13, 2015 14:43
SQL - customer orders by month
DECLARE @sql NVARCHAR(max), @selects NVARCHAR(max)
SET @sql = 'SELECT ';
SET @selects = '';
SELECT @selects = COALESCE(@selects + ', ', '') + ' (SELECT COUNT(DISTINCT O.OrderID)
FROM Orders O
WHERE O.CustomerID = C.CustomerID
AND O.OrderDate BETWEEN ''' + convert(NVARCHAR(MAX), [start_date], 102) +
''' AND ''' + convert(NVARCHAR(MAX), [end_date], 102) + ''' ) AS [' + [date_text] + ']' + CHAR(13)
FROM #dates ;
public static MongoDatabase Connect(string connectionString)
{
if (string.IsNullOrWhiteSpace(connectionString))
throw new System.ArgumentNullException("invalid connection string");
var mongoConnStr = MongoUrl.Create(connectionString);
MongoClient client = new MongoClient(mongoConnStr);
MongoServer server = client.GetServer();
if (server.State == MongoServerState.Disconnected)
public PagedCollection<TEntity> Read<TEntity>(string collectionName,
IMongoQuery query, IMongoSortBy sortBy, IMongoFields fields,
int page, int pageSize)
{
var connectionString = ".....";
MongoDatabase db = Connect(connectionString);
MongoCollection coll = db.GetCollection<TEntity>(collectionName);
MongoCursor<TEntity> foundItems = (null == query) ? coll.FindAllAs<TEntity>() : coll.FindAs<TEntity>(query);
@mizrael
mizrael / DynamicConfig_loading
Last active August 29, 2015 14:22
DynamicConfig - loading from file
var filename = "config.json";
var providerName = "json";
var configName = "myConfig";
dynamic config = Config.Load(providerName, configName, filename);
@mizrael
mizrael / directive.js
Last active August 29, 2015 14:23
AngularJS directive with function (no arguments)
myApp.directive('callbackDirective', function () {
return {
scope: {
callback: '&'
},
restrict: 'E',
templateUrl: 'my-template.html'
controller: ['$scope', function ($scope) {
$scope.foo = function () {
if ($scope.callback) {
@mizrael
mizrael / directive.js
Created June 24, 2015 15:36
AngularJS directive with function (and arguments)
myApp.directive('callbackDirective', function () {
return {
scope: {
callback: '&'
},
restrict: 'E',
templateUrl: 'my-template.html'
controller: ['$scope', function ($scope) {
$scope.foo = function (bar) {
if ($scope.callback) {
public interface IMyInterface
{
// blah
}
public class MyClass
{
public IEnumerable<IMyInterface> TheItems { get; set; }
}
var myClassInstance = new MyClass();
// blah
string jsonData = JsonConvert.SerializeObject(myClassInstance, Formatting.Indented, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
});
var myClassInstaceDeserialized = JsonConvert.DeserializeObject<MyClass>(jsonData, new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects
});