Instantly share code, notes, and snippets.

View constructor.js
var ConstructorName = (function() {
'use strict';
var variablePrivada = 0;
function ConstructorName(args) {
// enforces new
if (!(this instanceof ConstructorName)) {
return new ConstructorName(args);
}
View parcheesiTest.js
//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);
View probabilityTest.cs
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)))
{
View chefOdd.cs
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];
View jsonexample.js
{
   "@name": "WasteLands",
   "@tilesPerRow": "50",
   "@tilesPerColumn": "50",
   "@PixelsPerTile": "60",
   "tileType": [
      {
         "@name": "gold",
         "@weight": "10"
      },
View NullOrEmpty.cs
public static bool IsNullOrEmpty(string value) { if (value != null) return value.Length == 0; else return true; }
View Attachments_Basecamp.rb
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
View HourManagement.cs
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
View javascriptUrlParams
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