Skip to content

Instantly share code, notes, and snippets.

@SLaks
SLaks / Snippets.js
Created January 5, 2021 18:19
Console Snippets to manipulate YouTube Music playlists in bulk
// First, load jQuery:
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
////////////////////////////////////////////////////////////////////////////
// Remove all disliked songs:
for (const el of $('ytmusic-responsive-list-item-renderer:has([like-status="DISLIKE"])').get()) {
el.dispatchEvent(new MouseEvent('contextmenu'));
@SLaks
SLaks / Importer.cs
Created August 2, 2021 20:13
ShulCloud Import Script
// Run this in LINQPad, and add a reference to my https://github.com/ShomreiTorah/Libraries/tree/master/ShomreiTorah.Common
const string domain = "<TODO: insert domain here>";
static readonly Regex parseId = new Regex(@"action=edit_addresses&id=(\d+)");
static readonly Regex findSccsrf = new Regex(@"<input type=""hidden"" name=""sccsrf"" value=""(\w+)""/>");
bool dryRun = false;
async Task Main() {
var cookies = new CookieContainer();
@SLaks
SLaks / Console script.js
Last active July 12, 2021 23:09
Export services from Castlight
copy(await (async () => {
var lastId = localStorage.SLaks___lastExportedId || /* Paste the last ID from the spreadsheet here: */ "";
function takeWhile(cb) {
let found = false;
return x => {
if (found) return false;
if (cb(x)) return true;
found = true;
return true;
}
@SLaks
SLaks / LogModule.cs
Created October 22, 2012 15:30 — forked from pawelpabich/LogModule.cs
Faster Log4Net and NLog modules for Autofac
using System;
using System.Linq;
using Autofac;
using Autofac.Core;
using NLog;
using log4net;
using LogManager = NLog.LogManager;
namespace AutofacIdea
{
@SLaks
SLaks / ExcelResult.cs
Created July 4, 2012 02:40
ExcelExporter.Mvc – A simple ActionResult for returning Excel files from ASP.Net MVC actions using ExcelExporter
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Mvc;
namespace ExcelExporter.Mvc {
///<summary>An ActionResult that sends an Excel spreadsheet to the client.</summary>
public class ExcelResult : FilePathResult {
static readonly Dictionary<ExcelFormat, string> ContentTypes = new Dictionary<ExcelFormat, string> {
{ ExcelFormat.Excel2003, "application/vnd.ms-excel" },
@SLaks
SLaks / Boxing.cs
Created January 19, 2014 14:59
Non-boxing generic conversions
static void Main()
{
Console.WriteLine(X<int>.GetValue());
Console.WriteLine(X<long>.GetValue());
}
static class X<T> {
static int IntValue = 42;
static long LongValue = 64;
@SLaks
SLaks / Answer.cs
Created January 9, 2014 22:07
>(<
class X
{
void M<T>() { var x = (M<T>) < new X(); }
public static int operator <(Action a, X x) { return 0; }
public static int operator >(Action a, X x) { return 0; }
}
@SLaks
SLaks / Euler-14.cs
Last active January 1, 2016 18:48
How not to use LINQ to solve Project Euler #14
// http://projecteuler.net/problem=14
Enumerable.Range(1, 1000000).Select(s =>
Enumerable.Repeat(new List<long>(32) { s }, 1)
.First(list =>
Enumerable.Range(0, Int32.MaxValue)
.TakeWhile(i => list.Last() > 1)
.Aggregate(0, (index, unused) => {
list.Add(list.Last() % 2 == 0 ? list.Last() / 2 : 3 * list.Last() + 1);
return 0;
@SLaks
SLaks / SourceParser.cs
Created December 22, 2013 03:36
Parses PDBs from http://referencesource.microsoft.com/netframework.aspx and extracts source files to findable locations
//const string OriginalPath = @"C:\Users\SSL\Development\RefSrc\Source";
const string PDBPath = @"C:\Users\SSL\Development\Symbols\RefSrc\Symbols";
const string OriginalPath = @"C:\Users\SSL\Development\Symbols\RefSrc\Source\.NET 4.5\4.6.0.0";
const string TargetPath = @"C:\Users\SSL\Development\3rd-Party Source\Microsoft\.Net 4.5.1";
const string ErrorLog = TargetPath + @"\Errors.log";
static readonly Regex GoodLine = new Regex(@"^[a-zA-Z0-9\\:]{5}");
void Main() {
var pdbs = from file in Directory.EnumerateFiles(PDBPath, "*.pdb", SearchOption.AllDirectories)
group file by Path.GetFileName(file) into g
select g.OrderByDescending(p => new FileInfo(p).Length).First();
@SLaks
SLaks / DesignerThemeDictionary.cs
Created December 22, 2013 02:28
Trying to create a design-time ResourceDictionary of VS theme colors
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.Internal.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Platform.WindowManagement;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;