Skip to content

Instantly share code, notes, and snippets.

View mbalex99's full-sized avatar

Maximilian Alexander mbalex99

View GitHub Profile
@mbalex99
mbalex99 / SaltedHash
Created June 7, 2013 15:23
Salted Hash Password
public static class SaltedHash
{
public static byte[] GenerateSalt()
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
int minSaltSize = 16;
int maxSaltSize = 32;
Random random = new Random();
int saltSize = random.Next(minSaltSize, maxSaltSize);
@mbalex99
mbalex99 / SendEmail
Created June 7, 2013 15:24
C# Send Email
public void SendEmail(string fromEmailAddress, string fromName, string fromPassword, string host, int port,
string toEmailAddress, string toName, string subject, string body, bool isHtmlEmail)
{
var fromAddress = new MailAddress(fromEmailAddress, fromName);
var toAddress = new MailAddress(toEmailAddress, toName);
var smtp = new SmtpClient()
{
Host = host,
Port = port,
@mbalex99
mbalex99 / Loadable.js
Created June 13, 2013 16:08
Loadable Directive for Angularjs
'use strict';
Application.Directives.directive("loadable", function() {
return {
restrict: "A",
templateUrl: "/partials/loading/loadable.html",
transclude: true,
scope: {
loadable: "@"
@mbalex99
mbalex99 / ngInitial
Created September 3, 2013 18:24
setting and getting the initial value
app = angular.module 'forms', []
app.directive 'ngInitial', ->
restrict: 'A'
controller: ['$scope', '$element', '$attrs', '$parse', ($scope, $element, $attrs, $parse) ->
val = $attrs.sbInitial || $attrs.value
getter = $parse($attrs.ngModel)
setter = getter.assign
setter($scope, val)
]
DECLARE @intPage int;
DECLARE @intPageSize int;
SET @intPage = 1;
SET @intPageSize = 20;
DECLARE @intStartRow int;
DECLARE @intEndRow int;
SET @intStartRow = (@intPage -1) * @intPageSize + 1;
@mbalex99
mbalex99 / List Certificates
Created September 6, 2013 18:06
List Certificates
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My","LocalMachine")
$store.Open("ReadOnly")
$store.Certificates
@mbalex99
mbalex99 / AFNetworking Parsing
Created September 18, 2013 06:32
JSON AFNetworking
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"link"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary *jsonDict = (NSDictionary *) JSON;
NSArray *products = [jsonDict objectForKey:@"products"];
[products enumerateObjectsUsingBlock:^(id obj,NSUInteger idx, BOOL *stop){
NSString *productIconUrl = [obj objectForKey:@"icon_url"];
}];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response,
@mbalex99
mbalex99 / Range Query
Created September 18, 2013 20:39
DateTime Range Query
var rangeStart = new DateTime(2012, 1, 1);
var rangeEnd = new DateTime(2012, 12, 31);
var res = list
.Where(item => (item.StartTime < rangeStart ? rangeStart : item.StartTime) < (item.EndTime < rangeEnd ? item.EndTime : rangeEnd) )
.ToList();
@mbalex99
mbalex99 / Local Make Cert
Created December 12, 2013 21:28
Local Makecert
#### Run the Visual Studio Native Tools As an Administrator
#### The Exchange flag is VERY IMPORTANT
makecert -n CN=local.covertonight.com -sr LocalMachine -ss My -sky Exchange -pe
@mbalex99
mbalex99 / Bluebird Manual Promise
Created August 21, 2014 02:20
Manual Promise Resolution and Rejection with Bluebird and Q
var Promise = require('bluebird');
var fetchPostById = function(postId){
return new Promise(function(resolve, reject){
mySampleAsyncDatabaseFetch(postId, function(err, post){
if(err){
reject(err);
}
resolve(post);
});