Skip to content

Instantly share code, notes, and snippets.

View searope's full-sized avatar

Sea Rope searope

View GitHub Profile
@searope
searope / FuncScorer.py
Last active June 7, 2022 03:52
helper class to make custom mentrics easier in sklearn
import numpy as np
from sklearn.preprocessing import QuantileTransformer
from sklearn.metrics._scorer import _BaseScorer
class FuncScorer(_BaseScorer):
def _score(self, method_caller, estimator, X, y_true, sample_weight=None):
"""Evaluate predicted target values for X relative to y_true.
@searope
searope / multiprocessing.py
Last active May 17, 2022 16:57
Multiprocessing in Python with Multprocessing module
import random
import time
import multiprocessing as mp
import itertools as it
# just an example generator to prove lazy access by printing when it generates
def get_counter(limit=10):
for i in range(limit):
for j in range(limit):
print(f"YIELDED: {i},{j}")
@searope
searope / dictionary_values_permutations.py
Created May 17, 2022 14:41
permutates all elements in list values of a dictionary to return a dictionary with the same keys but single values
import itertools
my_dict = {'A':['D','E'],'B':['F','G','H'],'C':['I','J']}
keys, values = zip(*my_dict.items())
permutations_dicts = [dict(zip(keys, v)) for v in itertools.product(*values)]
# this will provide you a list of dicts with the permutations:
print(permutations_dicts)
#[{'A':'D', 'B':'F', 'C':'I'},
static void PrintTypes(LambdaExpression expr)
{
Console.WriteLine(expr);
ConstantExpression cexpr = expr.Body as ConstantExpression;
if (cexpr != null)
{
Console.WriteLine("\t{0}", cexpr.Type);
return;
}
BinaryExpression bexpr = expr.Body as BinaryExpression;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Extensions
{
public static class Extensions
{
@searope
searope / Helper.cs
Created December 18, 2019 20:20
Finds file or folder in parents folder
public static string FindUpperFileOrFolder(string name, DirectoryInfo dir = null)
{
dir = dir ?? new DirectoryInfo(Directory.GetCurrentDirectory());
var dirInfo = dir.GetDirectories(name).FirstOrDefault();
var fileInfo = dir.GetFiles(name).FirstOrDefault();
if (fileInfo == null && dirInfo == null)
{
return FindUpperFileOrFolder(name, dir.Parent);
}
@searope
searope / matplotlib.pyplot.py
Created June 25, 2019 15:42
matplotlib.pyplot tips and tricks
import matplotlib.pyplot as plt
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(9, 5))
ax1.set_title('Before Scaling')
sns.kdeplot(x['x1'], ax=ax1)
sns.kdeplot(x['x2'], ax=ax1)
ax2.set_title('After Robust Scaling')
sns.kdeplot(robust_scaled_df['x1'], ax=ax2)
sns.kdeplot(robust_scaled_df['x2'], ax=ax2)
ax3.set_title('After Min-Max Scaling')
@searope
searope / gist:cb6742acaa0b17a844f00d208f4071e7
Created July 14, 2017 17:59 — forked from istepura/gist:9222616
Generating permutations of arr in lexicographic order in C#
public IEnumerable<int[]> Permut(int[] arr){
while (true){
yield return arr;
var j = arr.Length - 2;
while (j >= 0 && arr[j] >= arr[j+1]) j--;
if (j < 0) break;
var l = arr.Length -1;
while (arr[j] >= arr[l]) l--;
@searope
searope / gist:34e787b49683d9ee725a3f7c07f944c3
Created July 14, 2017 17:59 — forked from istepura/gist:9222616
Generating permutations of arr in lexicographic order in C#
public IEnumerable<int[]> Permut(int[] arr){
while (true){
yield return arr;
var j = arr.Length - 2;
while (j >= 0 && arr[j] >= arr[j+1]) j--;
if (j < 0) break;
var l = arr.Length -1;
while (arr[j] >= arr[l]) l--;
@searope
searope / GetSidOfSecurityGroup.ps
Last active November 9, 2016 00:21
Get SID (security id) of a security group with PowerShell
(New-Object System.Security.Principal.NTAccount("Security Group Name")).Translate([System.Security.Principal.SecurityIdentifier]).Value