Skip to content

Instantly share code, notes, and snippets.

@oxfn
oxfn / which.ps1
Created March 3, 2019 19:36
Windows PowerShell 'which' analog
function which($app) {
foreach ($dir in $env:Path.Split(';')) {
$path = (Join-Path $dir $app);
if (Test-Path($path)) {
echo $path;
}
}
}
@oxfn
oxfn / rmsvc.sh
Last active February 17, 2019 22:55
Remove launchd service by grep regexp (Mac OS)
#!/bin/bash
# List services | Find pattern | Take 3-rd column | Pipe to `launchctl remove`
launchctl list | grep -iE "$1" | awk -F ' ' '{print $3}' | xargs -n1 -- launchctl remove
@oxfn
oxfn / rm-node-modules.sh
Last active December 19, 2018 16:26
Remove all node_modules recursively
find . \( -type d -name node_modules \) | sort -r | sed -e 's/node_modules\/.*/node_modules/' | uniq | xargs rm -r
const EOSIOHost = 'https://eos.guarda.co';
class EOS {
/**
* Get EOS RAM price per byte
* @returns {float} RAM price
*/
getRamPrice = async () => {
const { data } = await axios.post(`${EOSIOHost}/v1/chain/get_table_rows`, {
@oxfn
oxfn / gist:1bbc0b707bdffe1a8efc02b3a0676299
Created April 18, 2018 17:18
OpenSSL create self-signed certificate
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj '/C=Russia/ST=Moscow/L=Moscow/O=Company/OU=Org/CN=example.com'
@oxfn
oxfn / ProtectedStaticHandler.cs
Last active August 29, 2015 14:15
Role-based access control on static files in ASP.NET
// In latest Visual Studio web templates we have FormsAuthentication module
// disabled because of OWIN autentication. Thus it is impossible to
// configure static file access in Web.config only. In this case we can
// implement custom IHttpHandler which will check access to files.
// Here is example of role-based access control.
using System.Collections.Specialized;
using System.Web;
namespace Project