Skip to content

Instantly share code, notes, and snippets.

View forcewake's full-sized avatar

Pavel Nasovich forcewake

View GitHub Profile
@forcewake
forcewake / EnumExtensions.cs
Created June 30, 2013 20:47
Extension class for enums
public static class EnumExtensions
{
/// <summary>
/// Gets all items for an enum value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value">The value.</param>
/// <returns></returns>
public static IEnumerable<T> GetAllItems<T>(this Enum value)
{
$(function() {
var addMessage, connection, content, input, myName, status;
content = $("#content");
input = $("#input");
status = $("#status");
myName = false;
connection = new WebSocket("ws://127.0.0.1:1337");
connection.onopen = function() {
@forcewake
forcewake / prng.js
Created September 11, 2013 18:03 — forked from Protonk/prng.js
// Linear Congruential Generator
// Variant of a Lehman Generator
var lcg = (function() {
// Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes
// m is basically chosen to be large (as it is the max period)
// and for its relationships to a and c
var m = 4294967296,
// a - 1 should be divisible by m's prime factors
a = 1664525,
// c and m should be co-prime
@forcewake
forcewake / CreateInstance.cs
Last active December 27, 2015 22:49
CreateInstance for class with internal ctor
Type type = typeof (Bootstrap<>);
Type genericType = type.MakeGenericType(new Type[] {typeof (TModel)});
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
object instantiatedType = Activator.CreateInstance(genericType, flags, null, new HtmlHelper<TModel>[] { helper }, null);
return (Bootstrap<TModel>)instantiatedType;
public override int SaveChanges()
{
using (var scope = new TransactionScope())
{
var addedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Added).ToList();
var modifiedEntries = ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted || e.State == EntityState.Modified).ToList();
foreach (var entry in modifiedEntries)
{
ApplyAuditLog(entry);
using System;
using System.Collections.Generic;
using System.Linq;
namespace Curry
{
internal class Program
{
private static void Main(string[] args)
{
@forcewake
forcewake / iis-enabler.bat
Created December 15, 2013 20:59
Enable IIS feature on Windows 7, 8, 8.1
START /WAIT DISM /Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASP /FeatureName:IIS-ASPNET /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-CGI /FeatureName:IIS-ClientCertificateMappingAuthentication /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-CustomLogging /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DigestAuthentication /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-FTPExtensibility /FeatureName:IIS-FTPServer /FeatureName:IIS-FTPSvc /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HostableWebCore /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpLogging /FeatureName:IIS-HttpRedirect /FeatureName:IIS-HttpTracing /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-IISCertificateMappingAuthentication /FeatureName:IIS-IPSecurity /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-LegacyScripts /FeatureName:IIS-LegacySnapIn /FeatureNam
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Text;
using System.Threading;
namespace MapReduceWords
{
public class WordReducer
@forcewake
forcewake / fromScript.json
Last active August 29, 2015 13:56
Dynamic form from c# to jquery dynamic form
{
"action": "index.html",
"method": "get",
"html": [
{
"type": "p",
"html": "You must login"
},
{
"type": "text",
class Program
{
static void Main(string[] args)
{
ReflectedType reflectedType = new ReflectedType();
PropertyInfo intProperty = typeof(ReflectedType).GetProperty("SampleInt32");
SetAndGet(intProperty, reflectedType, 0);
SetAndGet(intProperty, reflectedType, 10);
SetAndGet(intProperty, reflectedType, 30);