Skip to content

Instantly share code, notes, and snippets.

@canton7
canton7 / Sample DataMapper model.rb
Last active September 10, 2018 03:16
Sinatra Auth in a Box
# From bcrypt-ruby gem
require 'bcrypt'
class User
include DataMapper::Resource
attr_accessor :password, :password_confirmation
property :id, Serial
property :username, String, :required => true, :length => (2..32), :unique => true
property :password_hash, String, :length => 60
public class ApplicationMutex : IDisposable
{
private static readonly ILog logger = LogManager.GetLogger(typeof(ApplicationMutex));
// This needs to have the prefix "Global\" in order to be system-wide
public const string MutexName = @"Global\MyApplicationNameMutex";
private Mutex mutex;
private bool acquired;
public readonly struct EquatableStruct : IEquatable<EquatableStruct>
{
private readonly float valueMember;
private readonly Version referenceMember;
public bool Equals(EquatableStruct other)
{
// Compare value types using == (or .Equals)
// Compare reference types for equality using Equals(object, object)
// to be safe to null references.
[*.cs]
# Standard EditorConfig settings
indent_style = space
indent_size = 4
# .NET code style settings
# See https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019
# This section lists all of the rules from the above link, in order
@canton7
canton7 / TreeViewExtensions.cs
Last active October 16, 2019 13:14
Read TreeView SelectedItem
public static class TreeViewExtensions
{
private static readonly object initialBindingTarget = new object();
public static object GetSelectedItem(DependencyObject obj) => obj.GetValue(SelectedItemProperty);
public static void SetSelectedItem(DependencyObject obj, object value) => obj.SetValue(SelectedItemProperty, value);
public static readonly DependencyProperty SelectedItemProperty =
DependencyProperty.RegisterAttached("SelectedItem", typeof(object), typeof(TreeViewExtensions), new FrameworkPropertyMetadata(initialBindingTarget, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (d, e) =>
{
@canton7
canton7 / ValidatingScreen.cs
Last active May 30, 2020 22:28
Caliburn Micro Validations
using Caliburn.Micro;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ValidationTest
{

Installing LaTeX + TeXstudio

  1. Grab MiKTeX 2.9 and install. It doesn't really matter whether you get the complete or basic system, as the basic system will download packages as needed.
  2. Grab TeXstudio and install.
  3. Fire up TeXstudio and hit Options -> Configure TexStudio.
  4. Under "Commands", change "Bibtex" from "bibtex %" to "bibtex8 %" (bibtex8 is later and greater and is needed for biblatex, which is better than bibtex for reference handling).
  5. Under "Quick Build", check "PdfLaTeX + Ldf Viewer". Not all LaTeX compilers were created equal, and Pdf is likely the format you'll want.
  6. If you're feeling adventurous, go to "Editor" and change the font family to "Consolas" :)
@canton7
canton7 / 0_main.md
Created January 6, 2012 13:45
Workflows for long-running feature branches

Workflows for long-running feature branches

These examples were created during a discussion with j416 on #github about how best to manage long-running feature branches.

The scenario is this: You have a long-running feature branch, based off master. The feature branch and master both touch the same parts of the same files, so you know that there will be conflicts when you finally merge the feature branch in. What can you do to minimise the conflicts?

public static class ReactiveExtensionsExtensions
{
public static async Task SubscribeAsync<T>(this IObservable<T> observable, Action<T> onNext, CancellationToken? cancellationToken = null)
{
CancellationToken token = cancellationToken ?? CancellationToken.None;
var cts = new TaskCompletionSource<bool>();
using(token.Register(() => cts.SetCanceled()))
{
observable.Subscribe(onNext, ex => cts.SetException(ex), () => cts.SetResult(true), token);
await cts.Task;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.