Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
smailliwcs / Base64Extensions.cs
Created September 22, 2020 15:25
Base64 serialization
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
public static class Base64Extensions
{
private static IFormatter GetFormatter()
{
return new BinaryFormatter();
@smailliwcs
smailliwcs / makepfx.bat
Created September 22, 2020 15:25
Creating self-signed certificates
@echo off
setlocal
set cn=%~1
if "%cn%" == "" goto :usage
makecert -sv "%cn%.pvk" -n "CN=%cn%" -b 01/01/2000 -e 12/31/2999 -r "%cn%.cer"
pvk2pfx -pvk "%cn%.pvk" -spc "%cn%.cer" -pfx "%cn%.pfx"
goto :eof
:usage
@smailliwcs
smailliwcs / ConditionalRequiredAttribute.cs
Created September 22, 2020 15:25
Conditional required validation
using System.ComponentModel.DataAnnotations;
using System.Reflection;
public sealed class ConditionalRequiredAttribute : RequiredAttribute
{
public override bool RequiresValidationContext
{
get { return true; }
}
@smailliwcs
smailliwcs / AutoGrid.cs
Created September 22, 2020 15:25
Automatic WPF grids
using System.Windows;
using System.Windows.Controls;
public class AutoGrid : Grid
{
protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
{
base.OnVisualChildrenChanged(visualAdded, visualRemoved);
SetCells();
}
@smailliwcs
smailliwcs / columns.js
Created September 22, 2020 15:25
TinyMCE plugin: columns
tinymce.PluginManager.add("columns", function (editor) {
function insert(count) {
editor.undoManager.transact(function () {
var row = editor.dom.create("div", { "class": "row" });
var width = Math.ceil(12 / count);
for (var index = 0; index < count; index++) {
var column = editor.dom.add(row, "div", { "class": "col-sm-" + width });
editor.dom.add(column, "p", {}, "Column " + (index + 1));
}
var node = editor.selection.getNode();
@smailliwcs
smailliwcs / paragraphs.js
Created September 22, 2020 15:25
TinyMCE plugin: paragraphs
tinymce.PluginManager.add("paragraphs", function (editor) {
function insert(place) {
var body = editor.getBody();
var paragraph = editor.dom.create("p");
place(paragraph, body);
editor.selection.setCursorLocation(paragraph);
editor.nodeChanged();
}
editor.addMenuItem("paragraph", {
@smailliwcs
smailliwcs / glyphicons.js
Created September 22, 2020 15:25
TinyMCE plugin: glyphicons
tinymce.PluginManager.add("glyphicons", function (editor) {
function insert(name) {
editor.insertContent("<span class='glyphicon glyphicon-" + name + "'></span>");
}
function getMenuItem(name) {
return {
text: name,
onclick: function () {
insert(name);
@smailliwcs
smailliwcs / revert.js
Created September 22, 2020 15:25
TinyMCE plugin: revert
tinymce.PluginManager.add("revert", function (editor) {
var content;
editor.on("LoadContent", function () {
content = editor.getContent();
});
editor.addMenuItem("revert", {
text: "Revert changes",
context: "file",
onclick: function () {
editor.undoManager.transact(function () {
@smailliwcs
smailliwcs / fileinput.html
Created September 22, 2020 15:25
jQuery/Bootstrap widget: fileinput
<script type="text/html" id="file-input-template">
<div class="input-group">
<input type="text" readonly="readonly" class="form-control" />
<label class="input-group-btn">
<span class="btn btn-primary">
Browse
<input type="file" class="sr-only" />
</span>
</label>
</div>
@smailliwcs
smailliwcs / dialog.html
Created September 22, 2020 15:25
jQuery/Bootstrap widget: dialog
<script type="text/html" id="modal-template">
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<span class="modal-title"></span>
</div>
<div class="modal-body"></div>
<div class="modal-footer"></div>
</div>