Skip to content

Instantly share code, notes, and snippets.

View goshki's full-sized avatar
👨‍💻
Such development, much coding. 😵‍💫

Adrian K. goshki

👨‍💻
Such development, much coding. 😵‍💫
View GitHub Profile
@goshki
goshki / digitAtSpecifiedPosition.js
Created September 7, 2010 13:01
JavaScript function to return a decimal digit at specific position (0-indexed, from the end) of a given number.
/**
* Returns a given power of ten (10 ^ 0 = 1, 10 ^ 1 = 10, 10 ^ 2 = 100, etc.).
*/
function powerOfTen( power ) {
var result = 1;
for ( i = 0; i < power; i++ ) {
result *= 10;
}
return result;
}
@goshki
goshki / ProjectEulerProblem1.scala
Created August 31, 2010 08:36
Scala example solutions for Project Euler problem 001
/**
* <p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples
* is 23.
*
* <p>Find the sum of all the multiples of 3 or 5 below 1000.
*
* @author Adrian K. <[email protected]>
*/
object ProjectEulerProblem001 {
def main( args : Array[String] ) : Unit = {
// Prints to browser console (Chrome, Firefox), no explicit ifs. Starts from 1.
for(i=0;i++<100;console.log([['fizz'][i%3],['buzz'][i%5]].join('')||i)); // 72 characters
// Writes to array 'a', no explicit ifs. Starts from 1.
for(a,i=0;i<100;a[i++]=([['fizz'][i%3],['buzz'][i%5]].join('')||i)); // 68 characters
// Returns an array (Firefox only), no explicit ifs, no explicit loops. Starts from 0.
Array.apply([],Array(100)).map((e,i)=>[['fizz'][i%3],['buzz'][i%5]].join('')||i) // 80 characters
# Most recent version of all records and creation date of the oldest version
#
# "id","version_since","version_until","content"
# "1","2010-06-01","2010-06-05","Initial text."
# "1","2010-06-05","2010-06-10","Modified text."
# "1","2010-06-10","2037-12-31","Final text."
# "2","2010-05-01","2010-05-31","Second initial text."
# "2","2010-05-31","2010-06-10","Modified second text."
# "2","2010-06-10","2010-06-15","Modified again second text."
# "2","2010-06-15","2037-12-31","Second final text."
# Given such a DB structure (MySQL):
#
# Table: module_cms_articles
#
# id | version_since | version_until | creation_date | creator_id | title | lead | content | visible
# ----+---------------------+---------------------+---------------------+------------+-----------------------+-----------------+--------------------------+---------
# 1 | 2010-05-12 19:57:05 | 2010-05-12 20:15:20 | 2010-05-12 19:57:05 | 1 | 1-st article | Introduction... | First article. | 0
# 1 | 2010-05-12 20:15:20 | 2010-05-12 20:27:28 | 2010-05-12 19:57:05 | 1 | 1-st article | Introduction... | First article. Extended. | 0
# 1 | 2010-05-12 20:27:28 | 2037-12-31 23:59:59 | 2010-05-12 19:57:05 | 1 | 1-st article modified | Introduction... | First Article. Extended. | 0
/**
* Calculates a compound interest (procent składany) for a given period of time
* with given annual interest rate, number of capitalizations and saving period.
*
* @param amount
* initial investment
*
* @param interestRate
* nominal annual interest rate (in decimal, so if interest rate is 5%,
* we give 0.05)