Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.RelyingParty;
namespace CRP.Authentication
public class LogonTime
{
public DayOfWeek DayOfWeek { get; set; }
public DateTime BeginTime { get; set; }
public DateTime EndTime { get; set; }
public LogonTime(DayOfWeek dayOfWeek, DateTime beginTime, DateTime endTime)
{
DayOfWeek = dayOfWeek;
BeginTime = beginTime;
public class ExchangeFunctions
{
private const string _username = "uname";
private const string _password = "password";
private const string _domain = "domain";
public static string CreateAppointment(string mailboxId, MyAppointment appt)
{
var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials(_username, _password, _domain);
private readonly string _storageUrl;
private readonly string _serverName;
private readonly string _sqlUsername;
private readonly string _sqlPassword;
private readonly string _storageAccountName;
private readonly string _storageKey;
private readonly string _storageContainer;
public string Backup(string database, string[] selectedTables, out string filename)
{
@anlai
anlai / gist:4399376
Created December 28, 2012 16:31
Function that deletes files out of an azure storage container, after X amount of days.
private readonly string _storageAccountName;
private readonly string _storageKey;
private readonly string _storageContainer;
private readonly int _cleanupThreshold;
private const string CloudStorageconnectionString = @"DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}";
public IEnumerable<string> BlobCleanup()
{
var storageAccount = CloudStorageAccount.Parse(string.Format(CloudStorageconnectionString, _storageAccountName, _storageKey));
var client = storageAccount.CreateCloudBlobClient();
@anlai
anlai / gist:5672028
Last active December 17, 2015 20:59
Better way to write linq queries
// inline method
var students = (
from student in RepositoryFactory.StudentRepository.Queryable
select new { FirstName = student.FirstName, LastName = student.LastName, FullName = string.Format("{0} {1}", student.FirstName, student.LastName) }
).ToList();
// using the let key word, looks cleaner
var students = (
from student in RepositoryFactory.StudentRepository.Queryable
let fullname = string.Format("{0} {1}", student.FirstName, student.LastName)
model.SectionDetails = (from section in repositoryFactory.SectionRepository.Queryable
let sequence = section.Course.CrossListedCourse == null ? section.Sequence : string.Format("{0} ({1} {2})", section.Sequence, section.Course.Subject, section.Course.CourseNumb)
let students = (decimal)section.ClassTimes.SelectMany(a => a.Students).Select(a => a.LoginId).Distinct().Count()
let responses = (decimal)section.ClassTimes.SelectMany(a => a.ClassTimeEvaluations).SelectMany(a => a.EvaluationResponses).Count()
let evals = section.ClassTimes.SelectMany(a => a.ClassTimeEvaluations).Count()
let instructors = section.ClassTimes.SelectMany(a => a.Instructors)
where section.Course == course || section.Course.CrossListedCourse == course
select new SectionDetail() { SectionId = section.Id, Sequence = sequence,
Students = (int)students, ResponseRate = ((responses)/(students*evals))*100,
InstructorList = instructors}
@anlai
anlai / playbook.yml
Created April 3, 2018 05:30
ansible playbook for building sonarqube server ... still not quite working yet
---
- hosts: all
become: yes
tasks:
- name: directory
file:
path: /opt/sonarqube
state: directory
- name: download/install
@anlai
anlai / playbook.yml
Created April 3, 2018 05:30
ansible playbook for building sonarqube server ... still not quite working yet https://devopscube.com/setup-and-configure-sonarqube-on-linux/
---
- hosts: all
become: yes
tasks:
- name: directory
file:
path: /opt/sonarqube
state: directory
- name: download/install
@anlai
anlai / localize-datetime.js
Created September 19, 2020 06:13
Simple script to convert an ISO 1806 UTC datetime to a localized date time string on page load.
const localizeDateTime = (function(){
window.addEventListener('load', function(){
const toLocalize = document.querySelectorAll('.localize-datetime');
toLocalize.forEach(element => {
let input = element.innerHTML;
let date = new Date(input);
element.innerHTML = `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`
});
});