Skip to content

Instantly share code, notes, and snippets.

View manhnguyenv's full-sized avatar

Manh Nguyen manhnguyenv

View GitHub Profile
@manhnguyenv
manhnguyenv / DataTableResultSet.cs
Created August 7, 2019 10:56 — forked from OllieJones/DataTableResultSet.cs
C# code for handling Ajax calls for the DataTables.net client table-rendering plugin.
/// <summary>
/// Resultset to be JSON stringified and set back to client.
/// </summary>
[Serializable]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class DataTableResultSet
{
/// <summary>Array of records. Each element of the array is itself an array of columns</summary>
public List<List<string>> data = new List<List<string>>();
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) =>
optionsBuilder
//Log parameter values
.EnableSensitiveDataLogging()
.UseSqlCe(@"Data Source=Blogging.sdf");
@manhnguyenv
manhnguyenv / modal-jq-bootstrap
Created August 1, 2019 02:39 — forked from marc-gist/modal-jq-bootstrap
bootstrap modal with jquery show button
<script>
/* to show modal via jquery clock event bound to id="modal_button_id" a/button/etc */
$(document).ready(function() {
$('#modal_button_id').click(function (event) {
$('#myModal').modal('show')
});
</script>
<div class="modal hide fade" id="modalID">
<div class="modal-header">
@manhnguyenv
manhnguyenv / code-block.html
Created July 19, 2019 07:01 — forked from mathewbyrne/code-block.html
A fun little experiment playing with CSS box shadows. I think it roughly works in Safari, Chrome and Firefox. No guarantees though.
<!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>
* {
@manhnguyenv
manhnguyenv / location.html
Created July 19, 2019 07:00 — forked from mathewbyrne/location.html
A small, single-page tool for getting your current geolocation.
<!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');
@manhnguyenv
manhnguyenv / UserWithCrypto.js
Created April 30, 2019 15:51 — forked from pdonham/UserWithCrypto.js
Sample code for Using JWTs for Authentication in RESTful Applications (http://sites.bu.edu/perryd/?p=259)
/*
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
@manhnguyenv
manhnguyenv / classes.js
Created April 5, 2019 09:08
pure javascript add class and remove class functions
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++) {
@manhnguyenv
manhnguyenv / comaprison.cs
Created April 5, 2019 07:44 — forked from huseyint/comaprison.cs
Property equality comparison on two objects
// 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))
{
@manhnguyenv
manhnguyenv / aes-example.cs
Created January 7, 2019 04:49 — forked from yetanotherchris/aes-example.cs
C# AES asymmetric encryption and decryption example
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);
@manhnguyenv
manhnguyenv / slugify.js
Created July 26, 2018 04:00 — forked from mathewbyrne/slugify.js
Javascript Slugify
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
}