Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
johnmmoss / object_create.js
Last active July 1, 2016 15:15
Creating an object using Object.create
'use strict'
var monkey = Object.create(Object.prototype,
{
name: {
value: "Hansel",
writable: true,
enumerable: true,
configurable: true
},
// JavaScript object is a collection of properties
var cat = { name: 'Felix', color:'blue' }
// We can get descriptor infomation out, descriptors returns:
// Object {value: "phil", writable: true, enumerable: true, configurable: true}
var descriptors = Object. getOwnPropertyDescriptor(cat, 'name')
// We can change the properties of an object using defineProperty:
Object.defineProperty(cat, ‘name’, {writable: false})
var cat = { name: 'Felix', color:'blue' }
// We can view the properties in the object by simply looping through:
for(var property in cat) {
document.write(key + ": " + cat[property] + ";"); // name: Felix; color:blue;
}
// Now we set enumerable to false
Object.defineProperty(cat, ‘name’, {ennumerable: false})
<div class="inputControl">
<input id="FollowUp" name="FollowUp" type="checkbox" value="true" />
<input name="FollowUp" type="hidden" value="false" />
</div>
// To disable and clear the checkbox, use "prop" NOT "attr"
$("#FollowUp").prop("disabled", checked);
$("#FollowUp").prop("checked", false);
// Options for setting values
checkbox.val("disabled", false); // Sets the value, but not if it is checked
checkbox.prop("disabled", false); // Disables the checkbox
checkbox.attr("disabled", false); // Also disables depending on version
checkbox.is(":checked"); // Returns checked value
@johnmmoss
johnmmoss / UserManager.cs
Created November 12, 2016 20:59
Sample UserManager
public class UserManager : UserManager<User>
{
public UserManager(IUserStore<User> store)
: base(store)
{
}
// This method is called by Owin therefore best place to configure your User Manager
public static UserManager Create(
IdentityFactoryOptions<UserManager> options, IOwinContext context)
@johnmmoss
johnmmoss / UserRole.cs
Created November 12, 2016 21:01
User and Role Entities
public class User : IdentityUser
{
}
public class Role : IdentityRole
{
public Role() : base() { }
public Role(string name) : base(name) { }
}
@johnmmoss
johnmmoss / SampleIdentityContext.cs
Created November 12, 2016 21:05
Sample Identity Context
public class TimesheetsContext : IdentityDbContext<User> , ITimesheetsContext
{
public IDbSet<Employee> Employees { get; set; }
public IDbSet<Department> Departments { get; set; }
public IDbSet<TimeCode> TimeCodes { get; set; }
public IDbSet<Timesheet> Timesheets { get; set; }
public TimesheetsContext()
: base("TimesheetsContext")
{
@johnmmoss
johnmmoss / IdentiyConfig.cs
Created November 12, 2016 21:07
Sample Identiy Config
public class IdentityConfig
{
public void Configuration(IAppBuilder app)
{
app.CreatePerOwinContext(() => new TimesheetsContext());
app.CreatePerOwinContext<UserManager>(UserManager.Create);
app.CreatePerOwinContext<RoleManager<Role>>((options, context) =>
new RoleManager<Role>(
new RoleStore<Role>(context.Get<TimesheetsContext>())));
@johnmmoss
johnmmoss / tail.ps1
Created January 16, 2017 11:06
Example tail command
function tail (){
Param(
[string] $file,
[int] $last = 10
)
Get-Content $file | Select-Object -Last $last
}