Skip to content

Instantly share code, notes, and snippets.

@bjhaid
bjhaid / fizzbuzz.py
Created November 20, 2013 03:07
Fizzbuzz in python
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:
@bjhaid
bjhaid / gist:7556952
Created November 20, 2013 03:00
Fizzbuzz in Java
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");
@bjhaid
bjhaid / gist:7435175
Created November 12, 2013 17:34
Declare, initialize and use a collection object on the fly
Set<String> varieties = new HashSet<String>() {{
add("Guatemala");
add("Tanzanian Peaberry");
add("Monsooned Malabar");
}};
@bjhaid
bjhaid / arabic2words.rb
Last active December 25, 2015 12:09
Conversion of arabic to english words
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?
@bjhaid
bjhaid / gist:6903904
Created October 9, 2013 16:19
ORA-01882: timezone region not found
ORA-01882: timezone region not found
Solution:
edit setenv.sh
you would find:
export JAVA_OPTS="-server -Xmx1024m"
and append:
@bjhaid
bjhaid / kata.txt
Created October 9, 2013 01:03
Wednesday Kata
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 ""
@bjhaid
bjhaid / fibonacci.rb
Created October 8, 2013 22:53
Fibonacci number in ruby
fib = Enumerator.new do |y|
j,i = 0,1
loop do
y.yield j
x = i
i += j
j = x
end
end
@bjhaid
bjhaid / gist:6884857
Created October 8, 2013 13:41
sqlplus Error 6 initializing SQL*Plus Message file sp1<lang>.msb not found
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
@bjhaid
bjhaid / gist:6874946
Created October 7, 2013 21:06
Failed to read artifact descriptor for + Maven
$ 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
@bjhaid
bjhaid / gist:6874209
Last active December 24, 2015 22:39
Memcached Errors
memcached: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
Below:
echo "/usr/local/lib/" > /etc/ld.so.conf.d/libevent-x86_64.conf
ldconfig
memcached -d -u nobody -m 1024 127.0.0.1 -p 11211