Skip to content

Instantly share code, notes, and snippets.

View fearofcode's full-sized avatar
🎵
Take that chance / All day long / Fucking up so fucking strong

Warren Henning fearofcode

🎵
Take that chance / All day long / Fucking up so fucking strong
View GitHub Profile
@fearofcode
fearofcode / App.xaml
Last active September 19, 2018 07:49
Simple window switching example with windows passing data to one another. Also shows a working TestStack.White test.
<Application x:Class="LoginExample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:LoginExample"
StartupUri="StartingWindow.xaml">
<Application.Resources></Application.Resources>
</Application>
@fearofcode
fearofcode / MVVMToolkit.cs
Created September 17, 2018 09:31
MVVM toolkit in a screenful of code
namespace MVVMToolkit
{
public abstract class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
@fearofcode
fearofcode / MainWindow.xaml
Created September 11, 2018 05:03
Simple async/await example in WPF
<Window x:Class="asyncawait.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:asyncawait"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="450">
<DockPanel>
<Button Name="buttonAsync"
@fearofcode
fearofcode / MainWindow.xaml
Created September 4, 2018 09:31
evaluating python code by shelling out and piping its output to a wpf window
<Window x:Class="databinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:databinding"
mc:Ignorable="d"
Title="MainWindow"
Height="800"
Width="800">
@fearofcode
fearofcode / MainWindow.xaml
Created September 4, 2018 08:52
simple .NET WPF BackgroundWorker test where long running task reports text back and it scrolls into a textbox that won't get messed up when you click/select it. the textbox scrolls to the end as lines come in.
<Window x:Class="databinding.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:databinding"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="400">
@fearofcode
fearofcode / wordcounter.cs
Last active September 2, 2018 23:06
simple C# concurrent word counter based on https://www.youtube.com/watch?v=B5xYBrxVSiE
using System;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Collections.Concurrent;
namespace wordcounter
{
class Program
{
@fearofcode
fearofcode / dynamiccompilation.cs
Created September 1, 2018 07:59
Simple working example of dynamically compiling a string of valid C# code and calling it
using System;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.Reflection;
namespace dynamiccompilation
{
class Program
{
@fearofcode
fearofcode / npgsql_example.cs
Created August 30, 2018 07:38
Simple working example of working with Npgsql.
using System;
using Npgsql;
namespace learningcsharp
{
class Program
{
static void Main(string[] args)
{
var connString = "Host=localhost;Username=arete;Database=arete";
@fearofcode
fearofcode / evaluator_server.py
Last active August 26, 2018 11:07
Evaluate a Python file and pipe it to stdout in a hot reload loop
import sys
import io
import traceback
import socketserver
class EvaluationHandler(socketserver.BaseRequestHandler):
def handle(self):
while True:
path = self.request.recv(2048).strip()
# http://stackoverflow.com/a/1667114
# https://kristerw.blogspot.com/2017/09/useful-gcc-warning-options-not-enabled.html
# various other places
CFLAGS = -Wall -Wextra -Wshadow -Werror -Wfatal-errors -pedantic -std=gnu11 -m64 \
-Wno-missing-braces -Wno-missing-field-initializers -Wformat=2 \
-Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith \
-Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline \
-Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code \
-Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \
-Wold-style-definition -Wduplicated-cond -Wduplicated-branches -Wrestrict \