Skip to content

Instantly share code, notes, and snippets.

@timiles
timiles / Ovod.srt
Created January 9, 2023 18:20
Ovod (Овод) / The Gadfly (1955) - original subtitles - slightly reformatted to improve results from Google translate
1
00:01:59,640 --> 00:02:02,000
Там наша родина, друзья мои.
2
00:02:06,400 --> 00:02:08,320
Сквозь бури и ветер,
3
00:02:09,760 --> 00:02:12,880
@timiles
timiles / objectUtils.ts
Last active June 6, 2022 15:18
get / set properties using dot notation
// property can have dot notation, eg 'parent.child.value'
export const getPropertyValue = (obj: any, property: string) =>
property.split('.').reduce((a, b) => (a ? a[b] : undefined), obj);
// property can have dot notation, eg 'parent.child.value'
export const setPropertyValue = (obj: any, property: string, value: any) => {
const keys = property.split('.');
const lastKey = keys.pop()!;
let currentObj = obj;
keys.forEach((key) => {
@timiles
timiles / AppState.tsx
Created April 29, 2022 11:25
Global app state using React Context
import { createContext, PropsWithChildren, useContext, useState } from 'react';
interface IContext {
getValue: <T>(key: string) => T | undefined;
setValue: <T>(key: string, value: T) => void;
}
const AppStateContext = createContext<IContext | undefined>(undefined);
const AppStateContextProvider = ({ children }: PropsWithChildren<{}>) => {
@timiles
timiles / fixes.reg
Created March 1, 2022 14:29
Windows 11 registry fixes
; Disable "Show more options" context menu
[HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32]
@=""
; Disable web search from start menu
[HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Windows\Explorer]
"DisableSearchBoxSuggestions"=dword:00000001
@timiles
timiles / SecretSanta.cs
Last active November 18, 2020 14:20
Generate and send random Secret Santa assignments via email
void Main()
{
var santas = new[]
{
// TODO: Fill out names and email addresses of all participants
new Santa("Person 1", "person1@example.com"),
new Santa("Person 2", "person2@example.com"),
new Santa("Person 3", "person3@example.com"),
new Santa("Person 4", "person4@example.com"),
};
@timiles
timiles / Rename-ItemsByDateTimeFromFileNameOrExifData.ps1
Last active September 20, 2020 15:55
PowerShell script to prefix files by DateTime from file name or Date Taken from EXIF data
function Get-DateTakenFromExifData {
param([String] $filePath)
try {
$imgData = New-Object System.Drawing.Bitmap($filePath)
try {
[Byte[]]$dateTakenExifData = $imgData.GetPropertyItem(36867).Value
[String]$dateString = [System.Text.Encoding]::ASCII.GetString($dateTakenExifData)
return [DateTime]::ParseExact($dateString, "yyyy:MM:dd HH:mm:ss`0", $null)
}
@timiles
timiles / Rename-ItemsByDateTaken.ps1
Last active July 3, 2023 18:49
PowerShell script to prefix files by Date Taken from EXIF data
function Get-DateTakenFromExifData {
param([String] $filePath)
try {
$imgData = New-Object System.Drawing.Bitmap($filePath)
try {
[byte[]]$dateTakenExifData = $imgData.GetPropertyItem(36867).Value
[string]$dateString = [System.Text.Encoding]::ASCII.GetString($dateTakenExifData)
return [datetime]::ParseExact($dateString, "yyyy:MM:dd HH:mm:ss`0", $null)
}
@timiles
timiles / Rename-ItemsByLastWriteTime.ps1
Created February 8, 2019 19:59
PowerShell script to rename files ordered by last modified date
$files = Get-ChildItem | Sort-Object LastWriteTime
For ($i=0; $i -lt $files.Length; $i++) {
$from = $files[$i].Name
$to = "$($i.ToString('000')) $from"
Write-Host "Renaming `"$from`" to `"$to`""
Rename-Item $from $to
}
@timiles
timiles / Base36.cs
Created October 25, 2018 09:14
Encode and decode between base 10 and base 36
public static class Base36
{
private const string Digits = "0123456789abcdefghijklmnopqrstuvwxyz";
private const string Max = "1y2p0ij32e8e7";
/// <summary>
/// Converts from base 10 to base 36.
/// </summary>
/// <param name="value">Value to convert</param>
using System;
using System.Text.RegularExpressions;
public static class EnumSnakeCaseExtensions
{
public static string ToSnakeCase(this Enum value)
{
return Regex.Replace(value.ToString(), @"(\p{Ll})(\p{Lu})", "$1_$2").ToLower();
}