This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sample implementation of quicksort and mergesort in ruby | |
| # Both algorithm sort in O(n * lg(n)) time | |
| # Quicksort works inplace, where mergesort works in a new array | |
| def quicksort(array, from=0, to=nil) | |
| if to == nil | |
| # Sort the whole array, by default | |
| to = array.count - 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fizzbuzz(num): | |
| i = 0 | |
| while (i < num): | |
| if (i % 15) == 0: | |
| print "fizzbuzz" | |
| elif (i % 5) == 0: | |
| print "Buzz" | |
| elif (i % 3) == 0: | |
| print "Fizz" | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FizzBuzz{ | |
| public static void main(String[] args){ | |
| int i = 0; | |
| while(i <= 100){ | |
| if ((i % 15) == 0) | |
| System.out.println("FizzBuzz"); | |
| else if ((i % 5) == 0) | |
| System.out.println("Buzz"); | |
| else if ((i % 3) == 0) | |
| System.out.println("Fizz"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Set<String> varieties = new HashSet<String>() {{ | |
| add("Guatemala"); | |
| add("Tanzanian Peaberry"); | |
| add("Monsooned Malabar"); | |
| }}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ONE_TO_NINETEEN = { 1=> "one", 2=> "two", 3=> "three", 4=> "four", 5=> "five", 6=> "six", 7=> "seven", 8=> "eight", 9=> "nine", 10=> "ten", 11=> "eleven", 12=> "twelve", 13=> "thirteen", 14=> "fourteen", 15=> "fifteen", 16=> "sixteen", 17=> "seventeen", 18=> "eighteen", 19=> "nineteen" } | |
| TENS = {20=>"twenty", 30=>"thirty", 40=>"forty", 50=>"fifty", 60=>"sixty", 70=>"seventy", 80=>"eighty", 90=>"ninety"} | |
| MULTIPLES = {100 => "hundred", 1000 => "thousand", 1000000 => "million", 1000000000 => "billion", 1000000000000 => "trillion" } #extending the numerals it can convert to words can be done by appending the key value pair to the MULTIPLES | |
| def arabic2words_under_100(num) | |
| word = "" | |
| while num > 19 | |
| divisor_num = (num / 10) | |
| num = (num % 10) | |
| (word << TENS[divisor_num * 10]) unless TENS[divisor_num * 10].nil? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ORA-01882: timezone region not found | |
| Solution: | |
| edit setenv.sh | |
| you would find: | |
| export JAVA_OPTS="-server -Xmx1024m" | |
| and append: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed into the method should result in an empty string being returned. | |
| format_words(['ninja', 'samurai', 'ronin']) # should return "ninja, samurai and ronin" | |
| format_words(['ninja', '', 'ronin']) # should return "ninja and ronin" | |
| format_words([]) # should return "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fib = Enumerator.new do |y| | |
| j,i = 0,1 | |
| loop do | |
| y.yield j | |
| x = i | |
| i += j | |
| j = x | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Error 6 initializing SQL*Plus | |
| Message file sp1<lang>.msb not found | |
| SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory | |
| Set $ORACLE_HOME correctly and this would sort it out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 | |
| [INFO] Scanning for projects... | |
| Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom | |
| [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5 | |
| Fix: | |
| Set/Unset proxy in $M2_HOME/conf/settings.xml |