Skip to content

Instantly share code, notes, and snippets.

@cobysy
cobysy / QueryInterceptor.cs
Created January 23, 2024 10:16
QueryInterceptor for Ef Core to apply SQL hints (Sql Server)
public class QueryInterceptor : DbCommandInterceptor
{
public const string TagPrefix = "QueryInterceptor:";
public override InterceptionResult<DbDataReader> ReaderExecuting(
DbCommand command,
CommandEventData eventData,
InterceptionResult<DbDataReader> result)
{
ManipulateCommand(command: command);
@cobysy
cobysy / PublicClientApplicationBuilder
Created August 5, 2022 11:01
PublicClientApplicationBuilder - get token for current user msal.net
var result = await PublicClientApplicationBuilder.CreateWithApplicationOptions(options: new()
{
ClientId = "8bxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
TenantId = "1exxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
})
.WithRedirectUri(redirectUri: "http://localhost")
.Build()
.AcquireTokenInteractive(scopes: "api://7fxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/some.web.api openid profile offline_access".Split(separator: ' '))
.WithAccount(account: PublicClientApplication.OperatingSystemAccount)
.WithPrompt(prompt: Prompt.NoPrompt)
@cobysy
cobysy / sserve.js
Created October 7, 2018 21:36
serve with https
#!/usr/bin/env node
// You need self-signed certs at first
// $ openssl req -nodes -new -x509 -keyout server.key -out server.cert
// Native
const https = require('https');
const fs = require('fs');
const {promisify} = require('util');
const dns = require('dns');
@cobysy
cobysy / deploy.sh
Created September 24, 2018 19:42
ghpages
git init
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:cobysy/somerepo.git
git push --force origin master:gh-pages
@cobysy
cobysy / uninstall-virtualenv.md
Created September 7, 2018 20:55
How-to uninstall virtualenv

sudo -i
PIP_REQUIRE_VIRTUALENV=false pip uninstall virtualenv

@cobysy
cobysy / orderBy.ts
Created August 25, 2018 13:27
TypeScript orderBy
declare global {
interface Array<T> {
sortBy(selector: (elem: T) => any): T[];
}
}
if (!Array.prototype.sortBy) {
Array.prototype.sortBy = function <T>(selector: (elem: T) => any): T[] {
return this.sort((a, b) => {
return selector(a) < selector(b) ? -1 : 1;
@cobysy
cobysy / JMdict_e.js
Created August 5, 2018 22:30
download JMdict_e.gz with node.js
const http = require('http');
const url = require('url');
const path = require('path');
const fs = require('fs');
function wget(source, { onStart, onProgress } = {}) {
return new Promise(function(y, n) {
const output = path.basename(url.parse(source).pathname);
const req = http.request(source,
@cobysy
cobysy / rsync.sh
Created August 5, 2018 16:51
rsync JMdict_e
#!/bin/sh
# v = verbose
# z = reduce the network transfer by adding compression
# P = combines the flags --progress and --partial.
# The first of these gives you a progress bar for the transfers and the second allows you to resume interrupted transfers
rsync -vzP ftp.edrdg.org::nihongo/JMdict_e .
@cobysy
cobysy / install-tensorflow-anaconda-osx.md
Created March 29, 2018 20:44
install-tensorflow-anaconda-osx

Was facing this stupid error message:

~/anaconda3 ❯❯❯ bin/conda install tensorflow Solving environment: failed

UnsatisfiableError: The following specifications were found to be in conflict:

  • scikit-image -> numpy[version='>=1.13.3,<2.0a0']
  • tensorflow Use "conda info " to see the dependencies for each package.