This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function string_to_slug (str) { | |
str = str.replace(/^\s+|\s+$/g, ''); // trim | |
str = str.toLowerCase(); | |
// remove accents, swap ñ for n, etc | |
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;"; | |
var to = "aaaaeeeeiiiioooouuuunc------"; | |
for (var i=0, l=from.length ; i<l ; i++) { | |
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function slugify(text) | |
{ | |
return text.toString().toLowerCase() | |
.replace(/\s+/g, '-') // Replace spaces with - | |
.replace(/[^\w\-]+/g, '') // Remove all non-word chars | |
.replace(/\-\-+/g, '-') // Replace multiple - with single - | |
.replace(/^-+/, '') // Trim - from start of text | |
.replace(/-+$/, ''); // Trim - from end of text | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string ivAsBase64; | |
string encryptedTextAsBase64; | |
string keyAsBase64; | |
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider()) | |
{ | |
// Store the IV (they can be stored if you don't re-use a key) | |
aes.GenerateIV(); | |
byte[] iv = aes.IV; | |
ivAsBase64 = Convert.ToBase64String(iv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shamelessly stolen and adapted from http://stackoverflow.com/questions/506096/comparing-object-properties-in-c | |
public static class Comparisons | |
{ | |
public static bool PublicInstancePropertiesEqual<T>(this T self, T to, params string[] ignore) where T : class | |
{ | |
if (self != null && to != null) | |
{ | |
var type = typeof(T); | |
foreach (var propertyName in type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Select(pi => pi.Name).Except(ignore)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var els = document.getElementsByClassName('current-class-name'); | |
removeClass(els, 'current-class-name'); | |
addClass(els, 'new-class-name'); | |
var el = document.getElementById('current-class-name'); | |
removeClass([el], 'current-class-name'); | |
addClass([el], 'new-class-name'); | |
function addClass(elements, className) { | |
for (var i = 0; i < elements.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
For this version we'll add a register method to add a user to the database using proper | |
password encryption. It also demonstrates how to add and use a method on a schema. | |
Reference: https://www.sitepoint.com/user-authentication-mean-stack | |
*/ | |
const mongoose = require('mongoose') | |
const crypto = require('crypto') | |
//const findOrCreate = require('mongoose-findorcreate') | |
//Set up ES6 Promises |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<p>Click the button to return the value of the string object.</p> | |
<button onclick="myFunction()">Try it</button> | |
<p id="demo"></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.toSlug = function(){ | |
st = this.toLowerCase(); | |
st = st.replace(/[\u00C0-\u00C5]/ig,'a') | |
st = st.replace(/[\u00C8-\u00CB]/ig,'e') | |
st = st.replace(/[\u00CC-\u00CF]/ig,'i') | |
st = st.replace(/[\u00D2-\u00D6]/ig,'o') | |
st = st.replace(/[\u00D9-\u00DC]/ig,'u') | |
st = st.replace(/[\u00D1]/ig,'n') | |
st = st.replace(/[^a-z0-9 ]+/gi,'') | |
st = st.trim().replace(/ /g,'-'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Navigation Test</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | |
<script> | |
var isTouchDevice = 'ontouchstart' in document.documentElement; | |
window.onload = function () { | |
var where = document.getElementById('where'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Shadows Test</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<style> | |
* { |
OlderNewer