Skip to content

Instantly share code, notes, and snippets.

@wtarr
wtarr / ApplicationLauncher.cs
Last active April 21, 2024 11:46
Template to build a CLI app launcher. Requires nugets CliWrap and Spectre.Console.
using CliWrap;
using Spectre.Console;
while (true)
{
var mainMenuResult = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Main Menu")
.PageSize(3)
.AddChoices(new [] { "1. Text Editors", "2. Exit"})
@wtarr
wtarr / main.cs
Last active March 12, 2017 22:03
Int to bit representation
void Main()
{
for (var i = 0; i <= 16; i++)
{
Console.WriteLine($"{i.ToString().PadLeft(2, '0')} {Convert.ToString(i, 2).PadLeft(8, '0')}");
}
}
// 00 00000000
// 01 00000001
@wtarr
wtarr / gist:4f92fa537dc7417498ddd9a4270045e8
Created March 2, 2017 09:28
Visual Studio command line build + octopack run
msbuild mysolution.sln /t:Build /p:Configuration=Debug /p:Platform="Any CPU" /p:RunOctoPack=true
@wtarr
wtarr / gist:b9e607e0e4f9483e7b57456485dd146e
Created June 14, 2016 12:38
Phoenix deps compile issue
web3> iex -S mix phoenix.server
Eshell V7.3 (abort with ^G)
==> (compile)
==> gettext
Compiled src/gettext_po_parser.yrl
Compiled src/gettext_po_parser.erl
Compiled lib/gettext/extractor_agent.ex
Compiled lib/gettext/backend.ex
Compiled lib/gettext/interpolation.ex
Compiled lib/gettext/po/plural_translation.ex
@wtarr
wtarr / portexample.ex
Last active April 8, 2016 17:50
Elixir to C# port example, based on http://stackoverflow.com/a/25342599
defmodule PortExample do
def start_exe(exe_name, arguments) do
# start the executable process for what settings mean see http://erlang.org/doc/man/erlang.html#open_port-2
port = Port.open({:spawn_executable, exe_name}, [{:args, arguments}, :stream, :binary, :exit_status, :hide, :use_stdio, :stderr_to_stdout])
# spawn a listening process
handle_output(port)
# return the port
port
end
@wtarr
wtarr / Eth0_interface_manager
Created December 12, 2014 10:50
Quick and dirty eth0 interface toggling GUI for testing purposes
from Tkinter import *
from subprocess import check_output
import ttk, os, sys
def disableConnection():
global currentstatus
try:
os.popen('sudo ifdown eth0', 'r', 1)
print 'Connection disabled'
currentstatus.set('down')
@wtarr
wtarr / index.html
Last active August 29, 2015 13:56
Simple web worker example
<html>
<head>
<title>Web worker example</title>
</head>
<body>
<script>
var worker = new Worker("worker.js");
worker.onmessage = function(e) {
@wtarr
wtarr / gist:6764547
Created September 30, 2013 14:21
Greatest Common denominator
private float GreatestCommonDenominator(float a, float b)
{
// http://en.wikipedia.org/wiki/Euclidean_algorithm
if (b == 0)
{
return a;
}
return GreatestCommonDenominator(b, a%b);
}
@wtarr
wtarr / qunittest.js
Created August 17, 2013 17:22
Qunit test of ko observable array after a (mocked) ajax call
module("module", {
setup: function () {
$.mockjax( {
url: "*",
responseTime: 1,
dataType: 'text/json',
responseText: [{'name' : 'wally'},{ "name":"molly" }]
});
},
teardown: function () {
@wtarr
wtarr / mockjaxsample.js
Last active December 21, 2015 01:59
Mockjax test: All calls to the server will be intercepted and replaced with the mockjax response text. Output will be MOCKJAX!!!! x 3
$(document).ready( function() {
$.mockjax({
// This should trigger a success and use my data
// as oppose to the data received from server
url: "http://localhost:8000/",
responseTime: 10,
dataType: 'text/json',
responseText: { "name" : "MOCKJAX!!!!" }
});