Skip to content

Instantly share code, notes, and snippets.

View dranger003's full-sized avatar

DAN™ dranger003

  • Canada
  • 15:25 (UTC -05:00)
View GitHub Profile
@dranger003
dranger003 / ConvertToImagesAsync.cs
Created June 3, 2024 02:00
Convert PDF to images using C# and the Windows Runtime (no third party dependencies).
// csproj:
// <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
// <ItemGroup><PackageReference Include="System.Drawing.Common" Version="8.0.6" /></ItemGroup>
using System.Drawing;
using System.Drawing.Imaging;
using Windows.Data.Pdf;
using Windows.Storage;
using Windows.Storage.Streams;
@dranger003
dranger003 / run_model_stream.py
Created May 25, 2024 22:51
Phi-3-Vision-128K-Instruct Stream
# run_model_stream.py
import sys
import re
import os
import queue
import threading
import torch
from PIL import Image
@dranger003
dranger003 / server.py
Last active September 21, 2024 10:35
Phi-3-Vision-128K-Instruct Quick Local API
# server.py
# uvicorn server:app --reload
import base64
import queue
import threading
import torch
from PIL import Image
from io import BytesIO
#!/bin/bash
set -e
# Check if miniconda3 is installed
if [ ! -d "miniconda3" ]; then
echo "miniconda3 directory not found, please run the init.sh script first"
exit 1
fi
# Source Conda shell script
#!/bin/bash
set -e
# Update sudoers file
if [ -f /etc/sudoers ]; then
sudo perl -i -pe 's/(^%sudo.*)(ALL=\(ALL:ALL\) ALL)/$1ALL=\(ALL:ALL\) NOPASSWD:ALL/' /etc/sudoers
else
echo "/etc/sudoers not found, check your system configuration"
exit 1
fi
@dranger003
dranger003 / Enable_vt100_csharp.cs
Created January 27, 2018 21:13 — forked from tomzorz/Enable_vt100_csharp.cs
Enable VT100 for the current console window from .NET Core
using System;
using System.Runtime.InteropServices;
namespace Vt100Test
{
public class Program
{
// ReSharper disable InconsistentNaming
@dranger003
dranger003 / ffmpeg-hevc-encode-nvenc.md
Created January 21, 2018 19:23
This gist shows you how to encode specifically to HEVC with ffmpeg's NVENC on supported hardware, with a two-pass profile and optional CUVID-based hardware-accelerated decoding.

Encoding high-quality HEVC content with FFmpeg - based NVENC encoder on supported hardware:

If you've built ffmpeg as instructed here on Linux and the ffmpeg binary is in your path, you can do fast HEVC encodes as shown below, using NVIDIA's NPP's libraries to vastly speed up the process.

Now, to do a simple NVENC encode in 1080p, (that will even work for Maxwell Gen 2 (GM200x) series), start with:

ffmpeg  -i <inputfile>  \
-filter:v hwupload_cuda,scale_npp=w=1920:h=1080:format=nv12:interp_algo=lanczos,hwdownload \

-c:v hevc_nvenc -profile main -preset slow -rc vbr_hq \

@dranger003
dranger003 / ESP8266-ZeroCrossTriac-Timer0
Created June 29, 2017 23:52
ESP8266 (WEMOS D1) Zero Cross Triac using Timer0 (higher resolution/quality than Timer1)
#define TIMR_OVRHD 7000
uint8_t _z = 0;
uint32_t _v = 20000;
void ICACHE_RAM_ATTR _ISR0() {
if (_z == 1) {
_z = 2;
timer0_write(ESP.getCycleCount() + 8000); // 8000 = 100us, 80000 = 1ms
digitalWrite(D2, HIGH);
#define TRIAC_PIN 5
#define ZERO_CROSS_PIN 4
#define DEBOUNCE_TIME 9000 //9ms - 10ms is the pulse period
static uint32_t lastPulse = 0;
static uint16_t period = 5000; //5ms - 50% for each half wave
void ICACHE_RAM_ATTR onTimerISR(){
if(GPIP(TRIAC_PIN)){//OUTPUT is HIGH
GPOC = (1 << TRIAC_PIN);//low
// RefObj.h : includes CRefObject, CRefAutoPtr
//
// Written by "Daniel Ranger" <[email protected]>
// Copyright (c) 2009 Daniel Ranger
//
// DESCRIPTION
//
// CRefAutoPtr is a smart pointer class to manage reference count within
// a CRefObject class. A normal smart pointer class manages reference
// count within its own class however in this implementation you must