Skip to content

Instantly share code, notes, and snippets.

View forcewake's full-sized avatar

Pavel Nasovich forcewake

View GitHub Profile
@forcewake
forcewake / cuda_11.8_installation_on_Ubuntu_22.04
Created November 20, 2023 20:26 — forked from agentcoops/cuda_11.8_installation_on_Ubuntu_22.04
Instructions for CUDA v11.8 and cuDNN 8.7 installation on (wsl) Ubuntu 22.04 for PyTorch 2.0.0
#!/bin/bash
### steps ####
# verify the system has a cuda-capable gpu
# download and install the nvidia cuda toolkit and cudnn
# setup environmental variables
# verify the installation
###
### to verify your gpu is cuda enable check
@forcewake
forcewake / extractTextBetweenCurlyBraces.js
Created June 5, 2015 12:55
Getting content between curly braces in javascript regex
var found = [], // an array to collect the strings that are found
rxp = /{([^}]+)}/g,
str = "a {string} with {curly} braces",
curMatch;
while( curMatch = rxp.exec( str ) ) {
found.push( curMatch[1] );
}
console.log( found ); // ["string", "curly"]
/*
Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
Microsoft Open Technologies would like to thank its contributors, a list
of whom are at http://aspnetwebstack.codeplex.com/wikipage?title=Contributors.
Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You may
obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@forcewake
forcewake / EnumerableExtensions.cs
Created March 7, 2014 06:30
Sorting expression dynamically using LINQ
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
public static class EnumerableExtensions
{
public static IEnumerable<T> OrderBy<T>(this IEnumerable<T> collection,
string columnName, SortDirection direction = SortDirection.Ascending)
{
ParameterExpression param = Expression.Parameter(typeof(T), "x"); // x
@forcewake
forcewake / lut3d.py
Created May 16, 2019 16:37 — forked from arsenyinfo/lut3d.py
Apply 3D LUT to an image. It's not optimized yet, however works as an acceptable PoC
from functools import partial
import numpy as np
from tqdm import tqdm
LUT_SIZE = 33
def _convert(pixel, lut):
r, g, b = map(lambda x: round((x / 255) * LUT_SIZE - 1), pixel)
idx = r + g * LUT_SIZE + b * (LUT_SIZE ** 2)

NPoco/PetaPoco stored procedures with named strong type parameters

StoredProcedures.tt file automatically generates a C# code file with calsses and methods corresponding to your database stored procedure definitions. This is then used to simply call stored procedures within NPoco/PetaPoco and avoid magic strings and parameter type guessing. It also supports output parameters.

Stored procedures naming conventions

In order to have your stored procedure calls well structured there are particular yet simple naming conventions you should follow when creating your stored procedures:

  1. Name your stored procedures as ClassName_Method
  2. If a particular stored procedure shouldn't be parsed you should omit underscore character in its name; this will make it private from the perspective of your C# as it will only be accessible to other stored procedures but won't be parsed.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add
key="nuget.org"
value="https://api.nuget.org/v3/index.json"
protocolVersion="3" />
<add
key="sharper-c"
value="https://www.myget.org/F/sharper-c/api/v3/index.json"
/**
* check if a selector match a given Node element
* see https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
* @param element element to check
* @param selector selector to check
* @return true if there is a match
*/
export function matches(element: HTMLElement, selector: string): boolean {
var matches = (<any> element).matches || (<any> element).webkitMatchesSelector || element.msMatchesSelector || (<any> element).mozMatchesSelector || (<any> element).oMatchesSelector;
matches = matches.bind(element);
@forcewake
forcewake / HomeController.cs
Created May 18, 2016 13:24 — forked from ahmad-moussawi/HomeController.cs
A view Render for Razor (aspnetcore RC2)
public class HomeController : Controller {
private readonly ViewRender view;
public HomeController (ViewRender view) {
this.view = view
}
public string Test () {
// render ~/Views/Emails/ResetCode
@forcewake
forcewake / iis-enabler.bat
Created December 15, 2013 20:59
Enable IIS feature on Windows 7, 8, 8.1
START /WAIT DISM /Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASP /FeatureName:IIS-ASPNET /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-CGI /FeatureName:IIS-ClientCertificateMappingAuthentication /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-CustomLogging /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DigestAuthentication /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-FTPExtensibility /FeatureName:IIS-FTPServer /FeatureName:IIS-FTPSvc /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HostableWebCore /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpLogging /FeatureName:IIS-HttpRedirect /FeatureName:IIS-HttpTracing /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-IISCertificateMappingAuthentication /FeatureName:IIS-IPSecurity /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-LegacyScripts /FeatureName:IIS-LegacySnapIn /FeatureNam