Skip to content

Instantly share code, notes, and snippets.

@tomasjurasek
tomasjurasek / ProcessKill
Last active August 29, 2015 14:03
process killer
Process currentProcess = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
if (processes.Count() > 1)
{
for (int i = processes.Count() -1; i > 0; i--)
{
processes[i].Kill();
}
}
@tomasjurasek
tomasjurasek / Hashing.cs
Last active April 21, 2016 19:07
Create hash with salt
public class Hashing
{
private readonly int SALT_SIZE = 16;
private readonly int HASH_SIZE = 32;
private byte[] salt;
private byte[] newSalt;
public string HashWithSalt(string passwordPlainText, string Username)
{
byte[] key;
@tomasjurasek
tomasjurasek / node.cs
Last active December 16, 2015 22:00
Node
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tree
{
class Program
{
@tomasjurasek
tomasjurasek / resource.cs
Created February 2, 2016 14:03
Embedded resource
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "AssemblyName.MyFile.txt";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}
}
@tomasjurasek
tomasjurasek / token.cs
Created February 12, 2016 09:53
Token Owin
public static AppUserManager Create(AppUserManager manager, IdentityFactoryOptions<AppUserManager> options, IOwinContext context)
{
// Configure validation logic for usernames
manager.UserValidator = new UserValidator<AppUser, int>(manager)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
};
// Configure validation logic for passwords
@tomasjurasek
tomasjurasek / app.cs
Created March 11, 2016 12:45
caller member name
public static string WEBSITE_SLOT_NAME => GetAppSettingsValue();
private static string GetAppSettingsValue([CallerMemberName]string propertyName = null)
{
return WebConfigurationManager.AppSettings[propertyName];
}
@tomasjurasek
tomasjurasek / gist:aa7ec6889f15e2beb5806dd8b3c37b6b
Created March 31, 2016 20:52 — forked from jonathanmoore/gist:2640302
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@tomasjurasek
tomasjurasek / reflection.cs
Created May 6, 2016 21:29
reflection class with list
class Program
{
static void Main(string[] args)
{
var person = new Person()
{
FirstName = "Tomas",
Surname = "Jurasek",
Persons = new List<Person>() { new Person { FirstName = "Test", Surname = "Test", Persons = null } }
};
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="%(Content.Link)"
SkipUnchangedFiles='true'
OverwriteReadOnlyFiles='true'
Condition="'%(Content.Link)' != ''" />
public static string ToQueryString(this NameValueCollection nvc)
{
StringBuilder sb = new StringBuilder();
foreach (string key in nvc.Keys)
{
if (string.IsNullOrEmpty(key)) continue;
string[] values = nvc.GetValues(key);
if (values == null) continue;