Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
smailliwcs / makepfx.bat
Created Sep 22, 2020
Creating self-signed certificates
View makepfx.bat
@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 Sep 22, 2020
Conditional required validation
View ConditionalRequiredAttribute.cs
using System.ComponentModel.DataAnnotations;
using System.Reflection;
public sealed class ConditionalRequiredAttribute : RequiredAttribute
{
public override bool RequiresValidationContext
{
get { return true; }
}
@smailliwcs
smailliwcs / AutoGrid.cs
Created Sep 22, 2020
Automatic WPF grids
View AutoGrid.cs
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 Sep 22, 2020
TinyMCE plugin: columns
View columns.js
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 Sep 22, 2020
TinyMCE plugin: paragraphs
View paragraphs.js
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 Sep 22, 2020
TinyMCE plugin: glyphicons
View glyphicons.js
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 Sep 22, 2020
TinyMCE plugin: revert
View revert.js
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 Sep 22, 2020
jQuery/Bootstrap widget: fileinput
View fileinput.html
<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 Sep 22, 2020
jQuery/Bootstrap widget: dialog
View dialog.html
<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>
@smailliwcs
smailliwcs / Forms.xaml
Last active Sep 22, 2020
Pixel-perfect WPF forms
View Forms.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="CheckBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Border Padding="0,6,0,5">
<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
You can’t perform that action at this time.