Skip to content

Instantly share code, notes, and snippets.

@Torvin
Torvin / twitter-login.py
Created April 2, 2023 06:33
Twitter challenge login
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from base64 import b64decode,b64encode
from urllib.parse import quote,parse_qs,urlsplit,urlparse
from random import randint
from bs4 import BeautifulSoup
import calendar
import requests
import hashlib
@Torvin
Torvin / RazorViewRenderer.cs
Last active November 26, 2018 23:42
Render a Razor view in ASP.NET Core 2.1. The view name should be in "~/path/to/view.cshtml" form
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
public class RazorViewRenderer

To convert a UUID in the 00000000-0000-0000-0000-000000000000 format to the format DEFINE_GUID macro uses

regexp: (.{8})-(.{4})-(.{4})-(..)(..)-(..)(..)(..)(..)(..)(..)

replace: with 0x$1, 0x$2, 0x$3, 0x$4, 0x$5, 0x$6, 0x$7, 0x$8, 0x$9, 0x${10}, 0x${11}

@Torvin
Torvin / ExpandableContentControl.cs
Created October 10, 2015 09:34
ExpandableContentControl
public class ExpandableContentControl : ContentControl
{
static ExpandableContentControl()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ExpandableContentControl), new FrameworkPropertyMetadata(typeof(ExpandableContentControl)));
ClipToBoundsProperty.OverrideMetadata(typeof(ExpandableContentControl), new FrameworkPropertyMetadata(true));
FocusableProperty.OverrideMetadata(typeof(ExpandableContentControl), new FrameworkPropertyMetadata(false));
}
#region public ExpandDirection RevealMode
@Torvin
Torvin / WeakDelegeate.cs
Last active November 12, 2015 23:26
WeakDelegeate
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
public class WeakDelegate<T>
where T : class
{
private static readonly Func<WeakDelegate<T>, T> InvokerFactory = CreateInvokerFactory();