Skip to content

Instantly share code, notes, and snippets.

View mbalex99's full-sized avatar

Maximilian Alexander mbalex99

View GitHub Profile
@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);
});
@mbalex99
mbalex99 / Express Vaidation Directive
Created August 26, 2014 19:11
ExpressJs Validation AngularJS Directive Example
/**
* Created by maximilianalexander on 8/15/14.
*/
angular.module('app').directive('validationMessage', function(){
return {
restrict: 'E',
templateUrl: 'client/partials/validation-message.html',
scope: {
errorModels: "=",
errorKey: "@"
@mbalex99
mbalex99 / gist:4581045b98aacb9eea84
Last active August 29, 2015 14:12
Specifying Android Build Variants for Different Environments
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
defaultConfig {
applicationId "com.epoqueinc.myapp"
minSdkVersion 15
targetSdkVersion 21
@mbalex99
mbalex99 / gist:dfd2627b00de56696596
Created December 25, 2014 15:59
Product Flavors Snippet
productFlavors {
prod {
packageName "com.mycompany.myapp"
}
dev {
packageName "com.mycompany.myapp.dev"
}
local{
packageName "com.mycompany.myapp.local"
}
@mbalex99
mbalex99 / gist:d64dc290f26aa47870b7
Created December 25, 2014 16:17
Getting Package Name
// In your application, you can retrieve it with getPackageName()
String packageName = getApplicationContext().getPackageName();
String apiUrl;
if(packageName.equals("com.mycompany.myapp")){
apiUrl = "myapi.com"
}
if(packageName.equals("com.mycompany.myapp.dev")){
apiUrl = "dev.myapi.com"
}
@mbalex99
mbalex99 / edencolor.swift
Created September 26, 2015 00:30
Eden Color Enum
//
// UIColorExtensions.swift
// Eden
//
// Created by Maximilian Alexander on 9/18/15.
// Copyright © 2015 Epoque. All rights reserved.
//
import UIKit
@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)
]