Skip to content

Instantly share code, notes, and snippets.

@anlai
anlai / Trakt Add Episode to List.js
Created January 2, 2023 04:19
Script that can be used in the browser console to add all the episodes on a Trakt season page to a list. (If used on a List page, it will remove all the episodes as well).
var lists = $('.trakt-icon-list-thick');
lists.each(function(){
this.click();
$(this).closest('a.list').siblings('.popover.with-list').find("li[data-list-id='{LIST_ID_HERE}']").click();
});
@anlai
anlai / setfanspeed.sh
Created November 18, 2020 06:44
Set fanspeed on Lenovo SA120 on Unraid
#!/bin/bash
# Script to change the fanspeed of the Lenovo SA120 server
# Depends on:
# sg3_utils https://slackware.pkgs.org/14.2/slackware-x86_64/sg3_utils-1.42-x86_64-1.txz.html
# fancontrol.py https://github.com/AndrewX192/lenovo-sa120-fanspeed-utility
SPEED=${1:-2}
installpkg sg3_utils-1.42-x86_64-1.txz
@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()}`
});
});
@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 / 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
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 / 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)
@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();
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)
{
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);