Skip to content

Instantly share code, notes, and snippets.

View amhed's full-sized avatar

Amhed Herrera amhed

  • San Francisco, CA
View GitHub Profile
@amhed
amhed / constructor.js
Created January 14, 2014 04:36
Ejemplo del constructor design pattern en javascript
var ConstructorName = (function() {
'use strict';
var variablePrivada = 0;
function ConstructorName(args) {
// enforces new
if (!(this instanceof ConstructorName)) {
return new ConstructorName(args);
}
@amhed
amhed / parcheesiTest.js
Created November 19, 2013 15:47
Example of TDD with NodeJS
//This uses mocha + should.js for running the unit tests
it('should allow players to take out a Pawn when a five(5/x) is rolled', function() {
//Since the dice throws random numnbers, we either need to throw it many times until
//we get the value we want, or just overwrite it's functionality.
//Here we chose to overwrite using the sinonJS mocking framework
sinon.stub(game, 'throwDices').returns([5,4]);
sinon.stub(game, 'lastDiceThrow').returns([5,4]);
game.enterPawn(0);
public void FichasRepartidasAJugadoresDebenSerBarajadas()
{
var probabilidad = 1m/28m;
int cantidadCajitas = 0;
for (int i = 0; i < 100; i++)
{
var juego = new JuegoDomino();
if (juego.Jugadores[0].Fichas[0].Equals(new Ficha(0, 0)))
{
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ChefOdd { class Program { static void Main(string[] args) { var qty = Convert.ToInt32(Console.ReadLine()); var testCases = new int[qty]; for (var i = 0; i < qty; i++) { var input = Convert.ToInt32(Console.ReadLine()); testCases[i] = input; } for (var i = 0; i < qty; i++) { GetBestPlace(testCases[i]); } Console.Read(); } private static void GetBestPlace(int testCase) { var initArray = Enumerable.Range(1, testCase).ToArray(); Console.WriteLine(DrawArray(initArray)); while (initArray.Length > 1) { var newArrSize = initArray.Length/2; var newArr = new int[newArrSize];
{
   "@name": "WasteLands",
   "@tilesPerRow": "50",
   "@tilesPerColumn": "50",
   "@PixelsPerTile": "60",
   "tileType": [
      {
         "@name": "gold",
         "@weight": "10"
      },
@amhed
amhed / NullOrEmpty.cs
Created October 1, 2013 02:47
IsNullOrEmpty decompiled source
public static bool IsNullOrEmpty(string value) { if (value != null) return value.Length == 0; else return true; }
@amhed
amhed / Attachments_Basecamp.rb
Created September 8, 2013 01:09
Ejemplo de como subir un attachment a Basecamp desde Ruby
require 'rubygems'
require 'json'
require 'net/http'
require 'uri'
#HTTP Request Objects
uri = URI.parse('https://basecamp.com/1823619/api/v1/projects/320356/attachments.json') #ruta de subir attachments en Basecamp
@https = Net::HTTP.new(uri.host,uri.port)
@https.use_ssl = true
@amhed
amhed / HourManagement.cs
Created June 17, 2013 16:14
Ejemplo de manejo de horas para Developers.do
using System; using System.Linq; namespace EjemploDevDo { public class HourManagement { //Supongo que esta lista viene de una BD o de algún servicio private static readonly DateTime[] listaFeriados2013 = new[] { new DateTime(2013,1,1), new DateTime(2013,1,6), new DateTime(2013,1,26), new DateTime(2013,2,27), new DateTime(2013,3,29), new DateTime(2013,5,1), new DateTime(2013,5,30), new DateTime(2013,8,16), new DateTime(2013,9,24), new DateTime(2013,11,6), new DateTime(2013,12,25), }; public static DateTime CalcularFechaRespuesta(DateTime fechaInicio, int cantidadHoras) { var horaInicio = 8; var horaTermino = 17; var fechaRespuesta = fechaInicio; //Se aplica la operacion de
@amhed
amhed / javascriptUrlParams
Created June 15, 2013 18:54
Getting url parameters with javascript (no plugins needed)
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
//Taken from stackoverflow
//http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values