Skip to content

Instantly share code, notes, and snippets.

View jessejjohnson's full-sized avatar

Jesse Johnson jessejjohnson

View GitHub Profile
@jessejjohnson
jessejjohnson / runDevBrowser.mjs
Created April 7, 2024 17:37 — forked from SomeHats/runDevBrowser.mjs
A hacky local version of cloudflare's browser rendering API. To use this, copy either runDevBrowser.ts or runDevBrowser.mjs and install the puppeteer and ws packages from npm. Run the dev server alongside wranger with `node runDevServer.mjs` or `tsx runDevServer.ts`
/* eslint-disable no-console */
/***
* This is a little server that emulates the protocol used by cloudflare's browser rendering API. In
* local development, you can run this server, and connect to it instead of cloudflare's (strictly
* limited) API. e.g. in your worker you might use a function like this:
*
* ```ts
* import { Browser, launch as launchPuppeteer } from '@cloudflare/puppeteer'
* function launchBrowser(env: Environment) {
* if (env.LOCAL_BROWSER_ORIGIN) {
@jessejjohnson
jessejjohnson / stealth.js
Last active February 15, 2024 19:55
Headless browser stealth scripts
/**
* Mock GPU information with real values. Check using: https://bot.sannysoft.com/
*/
WebGLRenderingContext.prototype.getParameter = function(origFn) {
const paramMap = {};
paramMap[0x9245] = "Google Inc. (NVIDIA Corporation)"; // UNMASKED_VENDOR_WEBGL
paramMap[0x9246] = "ANGLE (NVIDIA Corporation, Quadro P400/PCIe/SSE2, OpenGL 4.5.0)"; // UNMASKED_RENDERER_WEBGL
paramMap[0x1F00] = "WebKit"; // VENDOR
paramMap[0x1F01] = "WebKit WebGL"; // RENDERER
paramMap[0x1F02] = "WebGL 1.0 (OpenGL ES 2.0 Chromium)"; // VERSION
@jessejjohnson
jessejjohnson / ProcessAsyncHelper.cs
Created February 23, 2022 00:38 — forked from AlexMAS/ProcessAsyncHelper.cs
The right way to run external process in .NET (async version)
using System;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
public static class ProcessAsyncHelper
{
public static async Task<ProcessResult> ExecuteShellCommand(string command, string arguments, int timeout)
{
var result = new ProcessResult();
@jessejjohnson
jessejjohnson / IMapFrom.cs
Created October 4, 2021 19:11
AutoMapper Domain Mapping Profiles
using AutoMapper;
namespace Application.Common.Mappings
{
public interface IMapFrom<T>
{
void Mapping(Profile profile) => profile.CreateMap(typeof(T), GetType());
}
}
@jessejjohnson
jessejjohnson / UnitTest.cs
Created September 30, 2021 18:16
Notable code snippets discovered in real-world solutions
try
{
throw new Exception("test");
}
catch (Exception ex)
{
Assert.Equal("test", ex.Message);
}
@jessejjohnson
jessejjohnson / SnowflakeIdGenerator.cs
Last active April 4, 2023 12:39
Generate Twitter Snowflake ID's
public class SnowflakeIdGenerator
{
public const byte DefaultMachineIdBits = 6;
public const byte DefaultSequenceBits = 12;
private readonly long _machineId = 0;
private readonly byte _machineIdBits = 0;
private readonly byte _sequenceBits = 0;
private readonly long _maxSequence = 0;
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
private readonly object _lockObject = new object();
@jessejjohnson
jessejjohnson / ObjectExtensions.cs
Last active December 18, 2019 08:27
Fast (three times faster than BinaryFormatter) deep object copy extension method
using System.Collections.Generic;
using System.Reflection;
using System.ArrayExtensions;
namespace System
{
public static class ObjectExtensions
{
private static readonly MethodInfo CloneMethod = typeof(Object).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance);
@jessejjohnson
jessejjohnson / fiddle.css
Last active December 18, 2019 08:45
jsfiddle boilerplate
h1 {
color: #666;
}
@jessejjohnson
jessejjohnson / reset.css
Created August 8, 2018 05:28
Simple CSS Reset
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
margin: 0;
padding: 0;
border: 0;
font: inherit;
font-size: 100%;
vertical-align: baseline;
}
@jessejjohnson
jessejjohnson / bootstrap-wrapper.css
Created September 26, 2016 18:50 — forked from onigetoc/bootstrap-wrapper.css
Bootstrap wrapper no conflict - Wrap Bootstrap v3.3.6 CSS inside a div with the class .bootstrap-wrapper
.bootstrap-wrapper {font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
/*.bootstrap-wrapper body{margin:0}*/
.bootstrap-wrapper article, .bootstrap-wrapper aside, .bootstrap-wrapper details, .bootstrap-wrapper figcaption, .bootstrap-wrapper figure, .bootstrap-wrapper footer, .bootstrap-wrapper header, .bootstrap-wrapper hgroup, .bootstrap-wrapper main, .bootstrap-wrapper menu, .bootstrap-wrapper nav, .bootstrap-wrapper section, .bootstrap-wrapper summary{display:block}
.bootstrap-wrapper audio, .bootstrap-wrapper canvas, .bootstrap-wrapper progress, .bootstrap-wrapper video{display:inline-block;vertical-align:baseline}
.bootstrap-wrapper audio:not([controls]){display:none;height:0}
.bootstrap-wrapper [hidden], .bootstrap-wrapper template{display:none}
.bootstrap-wrapper a{background-color:transparent}
.bootstrap-wrapper a:active, .bootstrap-wrapper a:hover{outline:0}
.bootstrap-wrapper abbr[title]{border-bottom:1px dotted}
.bootstrap-wrapper b, .bootstrap-wrapper strong{font-weigh