Skip to content

Instantly share code, notes, and snippets.

View nathanchere's full-sized avatar
💭
I've moved to https://gitlab.com/nathanchere - these repos no longer maintained

Nathan Chere nathanchere

💭
I've moved to https://gitlab.com/nathanchere - these repos no longer maintained
View GitHub Profile
@nathanchere
nathanchere / a.ps1
Last active March 5, 2024 17:09
Determining if you are in the main script or being run/imported from another script
Import-Module ./common.psm1
Write-Host "This is a.ps1!"
./b.ps1
If(IsMain()){
Write-Host "This is a protected part of a.ps1"
}
@nathanchere
nathanchere / README.md
Created April 20, 2017 08:44
Inject git info into your builds

Use this as a pre-build step, either as part of your TeamCity/TFS/etc process or by adding it to the pre-build step of your project, like the following example. Assuming you have the script saved in a directory build located in the same directory as your .sln file:

<Project> 
  <!-- usual other stuff here //-->
  <!-- ... //-->
  <PropertyGroup>
    <PreBuildEvent>powershell -ExecutionPolicy RemoteSigned -File  $(SolutionDir)build\gitinject.ps1 $(ProjectDir)</PreBuildEvent>
@nathanchere
nathanchere / install-polybar-ex.sh
Last active September 8, 2020 10:11
Build Polybar on Fedora-ish systems
#!/usr/bin/env bash
# Builds Polybar on Fedora-based systems
# Tested on Fedora 25, Fedora 26 and Korora 25, untested on others
# To get started:
#
# wget -O- https://gist.githubusercontent.com/nathanchere/22491daf4f917b100a35e5c284a5fec5/raw/install-polybar-ex.sh | bash
sudo dnf install -y cmake @development-tools gcc-c++ i3-ipc jsoncpp-devel alsa-lib-devel wireless-tools-devel libmpdclient-devel libcurl-devel cairo-devel xcb-proto xcb-util-devel xcb-util-wm-devel xcb-util-image-devel
@nathanchere
nathanchere / UpcCode.cs
Last active March 31, 2020 06:31
EAN / UPC validation
public class UpcCode
{
public static bool IsValid(string code)
{
if (string.IsNullOrEmpty(code)) return false;
if (!code.All(char.IsDigit)) return false;
if (code.Length < 12 || code.Length > 13) return false;
var digits = code.Select(c => int.Parse(c.ToString())).Reverse().Skip(1).ToArray();
var checkBit = int.Parse(code.Last().ToString());
@nathanchere
nathanchere / Luid.cs
Last active March 5, 2020 11:03
LUID - Locally unique identifier
using System.Security.Cryptography;
using System.Text;
namespace TrotenLib
{
/// <summary>
/// Generate unique-enough pseudo-random identifiers where GUID is for some reason unsuitable
/// Explanation: https://stackoverflow.com/a/37099588/243557
/// </summary>
public static class LUID
@nathanchere
nathanchere / timedinput.ps1
Last active February 26, 2020 15:22
Powershell: timed input example
Function TimedPrompt($prompt,$secondsToWait){
Write-Host -NoNewline $prompt
$secondsCounter = 0
$subCounter = 0
While ( (!$host.ui.rawui.KeyAvailable) -and ($count -lt $secondsToWait) ){
start-sleep -m 10
$subCounter = $subCounter + 10
if($subCounter -eq 1000)
{
$secondsCounter++
@nathanchere
nathanchere / config.rasi
Created November 20, 2019 03:03
rofi config
/**
* rofi -dump-theme output.
* Rofi version: 1.5.4
**/
* {
colorTextHighlightEmphasis: bold underline rgba ( 190, 255, 0, 100 % );
colorTextDim: var(mutedPlum);
limeGreen: rgba ( 160, 255, 0, 100 % );
colorAccent: var(limeGreen);
colorText: var(ivoryShadow);
@nathanchere
nathanchere / EGKB---the-Endgame-Keyboard-_ANSI_.kbd.json
Last active June 2, 2019 17:13
EGKB - the Endgame Keyboard (ANSI)
[
{
"backcolor": "#555",
"name": "EGKB - the Endgame Keyboard (ANSI)",
"author": "Nathan Chere",
"radii": "11px",
"switchMount": "cherry",
"switchBrand": "cherry",
"switchType": "MX1A-C1xx",
"plate": true
@nathanchere
nathanchere / webstoemp-gulpfile.js
Created January 24, 2019 16:18 — forked from jeromecoupe/webstoemp-gulpfile.js
Gulp 4 sample gulpfile.js
"use strict";
// Load plugins
const autoprefixer = require("autoprefixer");
const browsersync = require("browser-sync").create();
const cp = require("child_process");
const cssnano = require("cssnano");
const del = require("del");
const eslint = require("gulp-eslint");
const gulp = require("gulp");
@nathanchere
nathanchere / Powershell profile
Created July 17, 2018 10:06
My powershell profile / prompt
# Requires nerdfont to display correctly
Import-Module posh-git
start-sshagent
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}