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 / nodeJs.crypto.symmetricCryptographyOfStrings.js
Created May 28, 2014 10:08
NodeJS - CRYPTO : Symetric Cryptography of Strings
var crypto = require('crypto')
// Encrypt/Decrypt a string
var key = "SecretKey"
, message = "This is the text to cipher!"
// Encrypting
var cipher = crypto.createCipher('des-ede3-cbc', key)
, cryptedMessage = cipher.update(message, 'utf8', 'hex')
cryptedMessage+= cipher.final('hex')
@GuillermoPena
GuillermoPena / nodeJs.scheduledLoop.js
Created May 28, 2014 09:59
NodeJS - Scheduled Loop
// How wait inside of loop...
// Countdown
var counter = 10
var countdown = function() {
console.log(counter)
counter--
return (counter > 0)
}
@GuillermoPena
GuillermoPena / nodeJs.json.objectAndFiles.js
Created May 28, 2014 09:55
NodeJS - JSON : Objects and files
//Read json object from json file.
//Write json object to json file
var fs = require('fs')
var util = require('util')
// __dirname is folder where script is running
// NOTE: Use always " in json file content
var cfgFile = __dirname + "/anything.json"
@GuillermoPena
GuillermoPena / nodeJs.loggingWithWinston.js
Created May 28, 2014 09:53
NodeJS - WINSTON : Logging with winston
// More info here: https://github.com/flatiron/winston
// Simple Example
var winston = require('winston')
var mongoTransport = require('winston-mongodb').MongoDB
var defaultLogger = winston
defaultLogger.level = 'silly'
defaultLogger.silly("Default logger")
@GuillermoPena
GuillermoPena / nodeJs.stdio.insertingArgumentsByConsole.js
Created May 28, 2014 09:52
NodeJS - STDIO : Inserting arguments by console
// More info here: http://sgmonda.github.io/stdio/
var stdio = require('stdio')
var opts = stdio.getopt({
'name': { key: 'n', description: 'Name', args: 1, mandatory: true },
'surnames': { key: 's', description: 'Surnames', args: 2 },
'age': { key: 'a', description: 'Age: ', args: 1 }
})
console.log( 'Your full name is ' + opts.name
+ ' ' + opts.surnames.join(' ')
@GuillermoPena
GuillermoPena / checkio.1.05.XsAndOsReferee.py
Created May 28, 2014 09:38
CheckIO - Home Challenge 5 : Xs and Os Referee
# CheckIO - Home Challenge 5 : Xs and Os Referee
# http://checkio.org
# Tic-Tac-Toe, sometimes also known as Xs and Os, is a game for two players (X and O)
# who take turns marking the spaces in a 3×3 grid.
# The player who succeeds in placing three respective marks in a horizontal, vertical,
# or diagonal rows (NW-SE and NE-SW) wins the game.
# But we will not be playing this game. You will be the referee for this games results.
# You are given a result of a game and you must determine if the game ends in a win
# or a draw as well as who will be the winner.
@GuillermoPena
GuillermoPena / checkio.1.03.HousePassword.py
Created May 28, 2014 09:11
CheckIO - Home Challenge 3 : House Password
# CheckIO - Home Challenge 3 : House Password
# http://checkio.org
# Stephan and Sophia forget about security and use simple passwords for everything.
# Help Nikola develop a password security check module.
# The password will be considered strong enough if its length is greater than or equal to 10 symbols,
# it has at least one digit, as well as containing one uppercase letter and one lowercase letter in it.
# The password contains only ASCII latin letters or digits.
# Input: A password as a string (Unicode for python 2.7).
# Output: Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean. In the results you will see the converted results.
@GuillermoPena
GuillermoPena / checkio.1.04.TheMostWantedLetter.py
Created May 28, 2014 09:08
CheckIO - Home Challenge 4 : The Most Wanted Letter
# CheckIO - Home Challenge 4 : The Most Wanted Letter
# http://checkio.org
# You are given a text, which contains different english letters and punctuation symbols.
# You should find the most frequent letter in the text. The letter returned must be in lower case.
# While checking for the most wanted letter, casing does not matter,
# so for the purpose of your search, "A" == "a".
# Make sure you do not count punctuation symbols, digits and whitespaces, only letters.
# If you have two or more letters with the same frequency, then return the letter which comes first in the latin alphabet.
# For example -- "one" contains "o", "n", "e" only once for each, thus we choose "e".
@GuillermoPena
GuillermoPena / checkio.1.02.Median.py
Created May 28, 2014 09:02
CheckIO - Home Challenge 2 : Median
# CheckIO - Home Challenge 2 : Median
# http://checkio.org
# A median is a numerical value separating the upper half of a sorted array of numbers from the lower half.
# In a list where there are an odd number of entities, the median is the number found in the middle of the array.
# If the array contains an even number of entities, then there is no single middle value,
# instead the median becomes the average of the two numbers found in the middle.
# For this mission, you are given a non-empty array of natural numbers (X).
# With it, you must separate the upper half of the numbers from the lower half and find the median.
@GuillermoPena
GuillermoPena / checkio.1.01.Non-uniqueElements.py
Created May 28, 2014 08:50
CheckIO - Home Challenge 1 : Non-unique Elements
# CheckIO - Home Challenge 1 : Non-unique Elements
# http://checkio.org
# You are given a non-empty list of integers (X).
# For this task, you should return a list consisting of only the non-unique elements in this list.
# To do so you will need to remove all unique elements (elements which are contained in a given list only once).
# When solving this task, do not change the order of the list.
# Example: [1, 2, 3, 1, 3] 1 and 3 non-unique elements and result will be [1, 3, 1, 3].
def checkio(data):