Skip to content

Instantly share code, notes, and snippets.

View matthewnitschke's full-sized avatar
⛰️

Matthew matthewnitschke

⛰️
View GitHub Profile
@matthewnitschke
matthewnitschke / PatternMatches.cs
Last active February 20, 2025 22:21
Simple wildcard matching in C#
public bool MatchesPattern(string pattern, string text)
{
pattern = pattern.Replace("%", @".+");
pattern = pattern.Replace("_", @".");
Regex regex = new Regex(pattern);
if (regex.IsMatch(text))
{
return true;
@matthewnitschke
matthewnitschke / formatString.js
Last active January 29, 2016 20:45
Formats a string to a pattern
function fomatPattern(value, pattern){
if (value){
var characters = pattern.replace(/#/g, "");
value = value.replace(new RegExp("["+characters+"]", 'gi'), "");
if (value){
return replace(value, pattern);
}
}
}
@matthewnitschke
matthewnitschke / patternFormatter.js
Created May 28, 2016 23:55
Takes a value and pattern for input and then returns a formatted string
function formatPattern(value, pattern) {
if (value){
var characters = pattern.replace(getWildcardRegex(), ""); // removes all wild cards
value = value.replace(new RegExp("["+characters+"]", 'gi'), ""); // removes all non wildcard characters in pattern
if (value){
return replace(value, pattern);
}
}
}
@matthewnitschke
matthewnitschke / Observify
Created July 9, 2016 02:37
Simple methods to force a variable to an observable. This is useful so when calling these variables you can just use: variableName()
function observifyArray(arr){
for(var i = 0; i < ko.unwrap(arr).length; i ++){
ko.unwrap(arr)[i] = observify(ko.unwrap(arr)[i]);
}
if (ko.isObservable(arr) && 'push' in arr){
return arr;
} else {
return ko.observableArray(arr);
}
}
ko.bindingHandlers.holdClick = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var timeoutId = 0;
var option = valueAccessor() || {};
$(element).mousedown(function () {
timeoutId = setTimeout(option, 1000);
}).bind('mouseup mouseleave', function () {
clearTimeout(timeoutId);
@matthewnitschke
matthewnitschke / testDate.js
Last active March 9, 2017 23:07
IE happy date check
function validDate(date){
var re = /(.{2})\/(.{2})\/((.{4})|(.{2}))/;
if (date.search(re) == -1){
return false;
}
var dt = date.split("/");
// month must be less than 13, greater than 0
var month = dt[0];
# remove old node from raspberry pi
sudo apt-get remove nodered -y
sudo apt-get remove nodejs nodejs-legacy -y
sudo apt-get remove npm -y # if you installed npm
# update node (with n)
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
@matthewnitschke
matthewnitschke / .hyper.js
Last active July 2, 2018 04:07
hyperterm one dark colors
backgroundColor: '#1E2127',
foregroundColor: '#ABB2BF',
colors: {
black: '#1E2127',
red: '#E06C75',
green: '#98C379',
yellow: '#D19A66',
blue: '#61AFEF',
magenta: '#C678DD',
cyan: '#56B6C2',
{
"last": "1.0.1",
"source": "pth"
}
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',