Skip to content

Instantly share code, notes, and snippets.

View GuillermoPena's full-sized avatar

Guillermo Peña GuillermoPena

  • Green Box Software
  • Madrid, Spain
View GitHub Profile
@GuillermoPena
GuillermoPena / checkio.1.08.romanNumerals.py
Created May 28, 2014 14:17
CheckIO - Home Challenge 8 : Roman Numerals
# CheckIO - Home Challenge 8 : Roman Numerals
# http://checkio.org
# Roman numerals come from the ancient Roman numbering system.
# They are based on specific letters of the alphabet which are combined
# to signify the sum (or, in some cases, the difference) of their values.
# The Roman numeral system is decimal based but not directly positional and does not include a zero.
# Roman numerals are based on combinations of these seven symbols:
# Symbol Value
# I 1 (unus)
@GuillermoPena
GuillermoPena / checkio.1.07.feedPingueons.py
Created May 28, 2014 11:32
CheckIO - Home Challenge 7 : Feed Pingeons
# CheckIO - Home Challenge 7 : Feed Pingeons
# http://checkio.org
# I start to feed one of the pigeons.
# A minute later two more fly by and a minute after that another 3.
# Then 4, and so on (Ex: 1+2+3+4+...).
# One portion of food lasts a pigeon for a minute, but in case there's not enough food for all the birds,
# the pigeons who arrived first ate first.
# Pigeons are hungry animals and eat without knowing when to stop.
# If I have N portions of bird feed, how many pigeons will be fed with at least one portion of wheat?
@GuillermoPena
GuillermoPena / checkio.1.06.speechModule.py
Created May 28, 2014 11:02
CheckIO - Home Challenge 6 : Speech Module
# CheckIO - Home Challenge 6 : Speech Module
# http://checkio.org
# Stephen's speech module is broken. This module is responsible for his number pronunciation.
# He has to click to input all of the numerical digits in a figure, so when there are big numbers it can take him a long time.
# Help the robot to speak properly and increase his number processing speed by writing a new speech module for him.
# All the words in the string must be separated by exactly one space character.
# Be careful with spaces -- it's hard to see if you place two spaces instead one.
# Input: A number as an integer.
# Output: The string representation of the number as a string.
@GuillermoPena
GuillermoPena / nodeJs.express.simpleWebService.js
Created May 28, 2014 10:19
NodeJS - EXPRESS : Simple Web Service
// How to create a simple web service with Express
// In App.js
// Dependencies
var express = require('express')
, http = require('http')
, port = 8080
// Application
var app = express()
@GuillermoPena
GuillermoPena / nodeJs.socketio.managingWebSockets.js
Created May 28, 2014 10:17
NodeJS - SOCKET.IO : Managing websockets
// Managing websocket with socket.io
// Setting a web socket and sending a message from client to server.
// Server side
var app = require('express')()
, util = require('util')
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)
, port = 8013
@GuillermoPena
GuillermoPena / nodeJs.ursa.asymmetricCryptologyWithSignature.js
Created May 28, 2014 10:16
NodeJS - URSA : Asymmetric Cryptology With Signature
// How to send message from A user to B user, encrypting it (asymetric cryptology) and sign it
var ursa = require('ursa')
, message = 'Hello world!'
, encoding = 'base64'
, buffer = new Buffer(message, 'ascii')
// Creating a pair of keys of user A (a private key contains both keys...)
console.log('Generating Keys Pair of user A...')
var keysA = ursa.generatePrivateKey()
@GuillermoPena
GuillermoPena / nodeJs.mocha.unitTesting.js
Created May 28, 2014 10:14
NodeJS - MOCHA : Unit Testing
// All you need to know about Mocha testing in 60 lines
// Mocha Testing: http://visionmedia.github.io/mocha/
// Installation: npm install -g mocha
// Run: mocha [test folder or test file]
// Example: mocha . (Run all js tests in folder)
//
// Usefull parameters:
// mocha -w . : Watch file changes and re-run tests
// mocha -d . : Debug mode
@GuillermoPena
GuillermoPena / nodeJs.ursa.asymmetricCriptography.js
Created May 28, 2014 10:13
NodeJS - URSA : Asymmetric Cryptology
// How to encrypt/decrypt with ursa module (asymmetric cryptology)
var ursa = require('ursa')
, message = 'Hello world!'
, encoding = 'base64'
// Creating a pair of keys (a private key contains both keys...)
console.log('Generating Keys Pair...')
var keys = ursa.generatePrivateKey()
// Making a private key
@GuillermoPena
GuillermoPena / nodeJs.crypto.simmetricCryptographyOfFiles.js
Created May 28, 2014 10:12
NodeJS - CRYPTO : Symmetric Cryptography of Files
var crypto = require('crypto')
, fs = require('fs')
var sourceFile = __dirname + "/testFile.txt"
, targetFile = __dirname + "/testEncryptedFile.txt"
, key = "SecretKey"
, algorithm = 'aes192' // Another algorithms: 'des-ede3-cbc'
, cipher = crypto.createCipher(algorithm, key)
, decipher = crypto.createDecipher(algorithm, key)
, rs = fs.ReadStream(sourceFile)
@GuillermoPena
GuillermoPena / nodeJs.dynamicNamedVariables.js
Created May 28, 2014 10:10
NodeJS - Variables with dynamic name
var varName1 = "varName2"
global[varName1] = "Hello World" // This is the important line ;)
var staticVarName = global[varName1]
console.log("Var1: Name/Value : varName1/" + varName1)
console.log("Var2: Name/Value : " + varName1 + "/" + global[varName1])
console.log("Static Var: Name/Value : staticVarName/" + staticVarName)