Skip to content

Instantly share code, notes, and snippets.

View ernestohs's full-sized avatar
🐙
coding in progress

Ernesto Herrera Salinas ernestohs

🐙
coding in progress
View GitHub Profile
@ernestohs
ernestohs / gist:3452638
Created August 24, 2012 16:36
if IndexOf isn't defined on IE
indexOf4Array = function () {
if (!Array.indexOf) {
Array.prototype.indexOf = function(obj) {
var length = this.length;
for (var i = 0; i < length; i++) {
if (this[i] === obj) {
return i;
}
}
return -1;
@ernestohs
ernestohs / gist:3452674
Created August 24, 2012 16:37
Avoid JS errors if the console object doesn't exist
(function () {
if (!window.console) {
console = {};
}
console.log = console.log || function () {
};
console.warn = console.warn || function () {
};
console.error = console.error || function () {
};
@ernestohs
ernestohs / gist:3779189
Created September 24, 2012 23:59
Factorial --noRecursion
var factorial = (function ()
{
var lanczos = function (n){
var z = n + 1;
var p = [1.000000000190015, 76.18009172947146, -86.50532032941677, 24.01409824083091, -1.231739572450155, 1.208650973866179E-3, -5.395239384953E-6];
/// \frac{\sqrt{2\pi}}{z}
var d1 = Math.sqrt(2 * Math.PI) / z;
var guid = (function () {
var _randomHex = function () {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
var _new = function () {
var UUID = [];
var n = 8;
while (n--) {
@ernestohs
ernestohs / ObjectCopy
Created February 26, 2013 17:03
Clone & Shallow
public static class ObjectCopy
{
/// <summary>
/// Clone by Deep Reflection
/// </summary>
/// <typeparam name="T">Type</typeparam>
/// <param name="source">Source Object</param>
/// <returns>Clone of Source</returns>
public static T Clone<T>(this T source)
{
@ernestohs
ernestohs / Base64.js
Last active December 14, 2015 06:09
Javascript Base64 encode/decode
;"strict";
window.Base64 = {
// private property
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode: function (input) {
var output = "";
$mail = New-Object System.Net.Mail.MailMessage
$mail.From = New-Object System.Net.Mail.MailAddress($from);
$mail.To.Add($to);
$mail.Subject = $subject;
$mail.Body = $body;
$smtp = New-Object System.Net.Mail.SmtpClient($smtpUrl);
@ernestohs
ernestohs / gobal.gitignore
Last active December 17, 2015 12:19
Global .gitignore
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@ernestohs
ernestohs / Array.Remove.js
Last active December 24, 2015 17:39
Array.remove for Javascript #ExtendingJavaScript
if (!Array.prototype.remove) {
Array.prototype.remove = function () {
var what, args = arguments, length = args.length, item;
while (length && this.length) {
what = args[--length];
while ((item = this.indexOf(what)) !== -1) {
this.splice(item, 1);
}
}
// Setup OAuthClient for Google
if (!string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["GoogleAppId"]) && !string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["GoogleAppSecret"]))
{
OAuthWebSecurity.RegisterClient(new GoogleOAuth2Client(ConfigurationManager.AppSettings["GoogleAppId"], ConfigurationManager.AppSettings["GoogleAppSecret"]), "Google", extraData);
}