Ruby bubble Sort Example
August 21, 2011 by admin · Leave a Comment
Ruby bubble Sort Example:
def bubbleSort(a)
swapped = true
while swapped == true
i = 0
swapped = false
while(i < a.length-1):
temp1 = a[i]
temp2 = a[i+1]
if (temp1 > temp2) then
a[i], a[i+1] = temp2, temp1
swapped = true
end
i += 1
end
end
return a
end
#From here down is example usage of the function!array = [1, 2, 6, 123, 32, -23, 2, -1, 2, 3, 123, 54]
puts “Before sorting:”
j = 0
while(j < array.length) #iterate through the loop, printing all values
print array[j]
print ‘ ‘
j += 1
end
puts “”bubbleSort(array)
puts “After sorting:”
k = 0
while(k < array.length)
print array[k]
print ‘ ‘
k += 1
end
svn status , xargs svn add
August 20, 2011 by admin · Leave a Comment
svn status | sed -n ‘/^\?/ s/\?\s+//; s/ /\ /p’ | xargs svn add
Erlang Strand Sort Example
August 20, 2011 by admin · Leave a Comment
Erlang Strand Sort Example:
-module(strand).
-compile(export_all).strand([]) -> [];
strand([H|T]) -> strand(T, [], [H], []).strand([], [], [], Final) -> Final;
strand([], [], Sorted, []) -> Sorted;
strand([], [], Sorted, Final) ->
Combined = combine(Sorted, Final, []),
Combined;
strand([], [A|B], Sorted, []) -> strand(B, [], [A], Sorted);
strand([], [A|B], Sorted, Final) ->
Combined = combine(Sorted, Final, []),
strand(B, [], [A], Combined);
strand([H|T], Temp, [C|_D], Final) ->
if
H=<C -> strand(T, Temp, [H,C|_D], Final);
H>C -> strand(T, [H|Temp], [C|_D], Final)
end.combine([], [], [H|T]) -> reverse(T, [H]);
combine([], [A|B], Acc) -> combine([], B, [A|Acc]);
combine([H|T], [], Acc) -> combine(T, [], [H|Acc]);
combine([H|T], [A|B], Acc) ->
if
H<A -> combine(T, [A|B], [H|Acc]);
H>=A -> combine([H|T], B, [A|Acc])
end.reverse([], Acc) -> Acc;
reverse([H|T], Acc) -> reverse(T, [H|Acc]).
Java MongoDB hello world
June 1, 2011 by admin · Leave a Comment
Java MongoDB hello world:
package com.mkyong.core;
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
public class App {
public static void main(String[] args) {
try {
// connect to mongoDB, ip and port number
Mongo mongo = new Mongo(“localhost”, 27017);
// get database from MongoDB,
// if database doesn’t exists, mongoDB will create it automatically
DB db = mongo.getDB(“yourdb”);
// Get collection from MongoDB, database named “yourDB”
// if collection doesn’t exists, mongoDB will create it automatically
DBCollection collection = db.getCollection(“yourCollection”);
// create a document to store key and value
BasicDBObject document = new BasicDBObject();
document.put(“id”, 1001);
document.put(“msg”, “hello world mongoDB in Java”);
// save it into collection named “yourCollection”
collection.insert(document);
// search query
BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put(“id”, 1001);
// query it
DBCursor cursor = collection.find(searchQuery);
// loop over the cursor and display the retrieved result
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
System.out.println(“Done”);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (MongoException e) {
e.printStackTrace();
}
}
}
Actual Proxy Tutorial HOWTO
June 1, 2011 by admin · Leave a Comment
Actual Proxy Tutorial HOWTO:
This article is NOT official Zimbra documentation. It is a user contribution and may include unsupported customizations, references, suggestions, or information.
Actual Proxy Notes Homepage
Please see Ajcody-Proxy-Notes
UPDATE PLEASE SEE THESE FIRST
Admin Guide Update
Our Administration Guide now has everything you should need to setup your proxy server.
Please see:
How To Enable Proxy
And Also Another More Current How-To Enable Proxy here: