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
/**
* 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)
# 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
# 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."
// 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
@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 = {
@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;
}
/**
* <p>
* What's the point (if there is any) and logic behind using/non-using "final" keyword for parameters in interface method and/or
* its implementation?
*/
public class Test {
// Example 1:
public static interface I {
void perform( final Boolean b ); // final on b
@goshki
goshki / run-java-app-with-classpath.sh
Created September 24, 2010 09:49
Bash command to run a Java app with automatically generated classpath based on jars in 'lib' folder.
# Automatically generate Java app classpath based on jars in 'lib' folder
javac -cp `echo lib/*jar | tr ' ' :` App.java
@goshki
goshki / FlashPunkKeyholdTest.as
Created February 28, 2011 15:46
Check for how long the given key has been held in FlashPunk mitigating the key-repeat under Linux
package {
import flash.utils.getTimer;
import net.flashpunk.*;
import net.flashpunk.utils.*;
/**
* <p>
* The reason to use such test is that under Linux holding a key triggers a key-repeat functionality after
* a moment and so, key-press events are generated. Therefore the Input.pressed() method will periodically
@goshki
goshki / argbOperations.as
Created April 12, 2011 10:33
ActionScript 3 basic operations on an ARGB (alpha, red, green, blue) color
package {
public static function argbDecombine( ARGB:uint ):Array {
return [ ARGB >> 24, ( ARGB >> 16 ) & 0xFF, ( ARGB >> 8 ) & 0xFF, ARGB & 0xFF ];
}
public static function argbCombine( ARGB:Array ):uint {
return argbCombine( ARGB[0], ARGB[1], ARGB[2], ARGB[3] );
}