Skip to content

Instantly share code, notes, and snippets.

@codecontemplator
codecontemplator / reformatpropertytest.cs
Last active February 3, 2018 17:05
reformat property
// "MyPropertyName" => "my_property_name"
// alt 0
var sb = new StringBuilder();
var chars = "MyPropertyName".ToCharArray();
for(var i = 0; i < chars.Length; ++i)
{
var c = chars[i];
if (Char.IsUpper(c) && i > 0)
sb.Append("_");
@codecontemplator
codecontemplator / Get-Token.template.ps1
Last active March 3, 2018 10:57
A powershell module for managing oauth clients and generating tokens
<#
.SYNOPSIS
Generate an oauth token.
.DESCRIPTION
Generate an oauth token for a specified client and environment
.PARAMETER ClientId
The oauth client id
class PooledCertificate : IDisposable
{
public X509Certificate2 Certificate { get; private set; }
private readonly ObjectPool<X509Certificate2> _certificatePool;
public PooledCertificate(ObjectPool<X509Certificate2> certificatePool)
{
Certificate = certificatePool.GetObject();
_certificatePool = certificatePool;
}
type Tree = Leaf Int
| Node (List Tree)
generateIdsForTree : Tree -> State Int Tree
generateIdsForTree t =
case t of
Node n -> State.traverse generateIdsForTree n |> State.andThen (\children -> State.state <| Node children )
Leaf l -> State.modify (\i -> i + 1) |> State.andThen (\_ -> State.get) |> State.andThen (\i -> State.state <| Leaf i)
sampleTree = Node
@codecontemplator
codecontemplator / Main.elm
Created June 17, 2018 19:58
Elm compiler problem causing a javascript runtime exception "TypeError: f is not a function"
import Html exposing (text)
import State exposing (State)
type alias QC = { qs : List Q }
type Q = Q { id : Int, qt : QT }
type QT = QT1 { subqs : List Q }
| QT2 { options : List QO }
@codecontemplator
codecontemplator / chrome-startmenu-items-update.ps1
Last active June 21, 2018 07:30
There is a problem with when adding chrome shortcuts to the start menu. The icons only show up as chrome icons and not as the actual web site icon. This script fixes it.
function Update-ChromeStartMenuItems
{
del "C:\Program Files (x86)\Google\Chrome\Application\chrome.VisualElementsManifest.xml.renamed" -ErrorAction SilentlyContinue
rename-item "C:\Program Files (x86)\Google\Chrome\Application\chrome.VisualElementsManifest.xml" "C:\Program Files (x86)\Google\Chrome\Application\chrome.VisualElementsManifest.xml.renamed"
$files = gci "C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Chrome-appar" -filter *.lnk
foreach($file in $files)
{
$file.LastWriteTime = [datetime]::Now
}
}
@codecontemplator
codecontemplator / formatduration.ijs
Last active September 27, 2018 17:46
create a string representing a duration in years, days, hours etc when given a duration in seconds
NB. ------------------------- calculate components -------------
calculateComponent=: dyad define
'a b' =. >y
<. (a | x) % b
)
calculateComponents=: monad define
duration =. y
// https://edabit.com/challenge/uhsik73PY7Y2XftzG
var alphabet = "abcdefghijklmnopqrstuvwxyz" + "abcdefghijklmnopqrstuvwxyz".ToUpper();
var vovels = "aeiouy" + "aeiouy".ToUpper();
var consonants = Regex.Replace(alphabet, $"[{vovels}]", "");
var type1word = $"(?<![{vovels}])(?<t1p1>[{consonants}]+)(?<t1p2>\\w+)";
var type2word = $"(?<![{consonants}]+)(?<t2>[{vovels}]\\w*)";
string CaptitalizeConditional(string word, bool doit)
@codecontemplator
codecontemplator / syncsubtitles.js
Created October 31, 2018 19:35
Synchronize the Subtitles
// https://edabit.com/challenge/H4of8EdxS98ikEaZd
function padNumber(number, size) {
var s = String(number);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
function addTimeVectors(timeStamp, timeIncrement) {
let weights = [1000, 60, 60, 60];
@codecontemplator
codecontemplator / shortestpath.js
Created November 17, 2018 17:05
Solution to edabit road navigation puzzle
// https://edabit.com/challenge/qQu4kxTEHapogmCgE
let roads = {
"graph": {
"directed": false,
"nodes": [
{ "id": 0 },
{ "id": 1 },
{ "id": 2 },
{ "id": 3 },