- www.gideondsouza.com
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
IUserRepository repo; | |
//this magically gets the right instance based on some config somewhere. |
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
class UserDisplay : UserControl | |
{ | |
UserDisplay(IUserRepository repo) | |
{//display the username or something here.. | |
} | |
} |
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
class FakeUserRepo : IUserRepository | |
{ | |
public string GetUserName(int id) | |
{ | |
return "FakeUser"; | |
} | |
} |
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
var fakeUserRepo = new Mock<IUserRepository>(); | |
fakeUserRepo.Setup(f => f.GetUserName(It.IsAny<int>)).Returns("FakeUser"); | |
//does the same thing as the class declaration | |
fakeUserRepo.Object;//this returns fake object of type IUserRepository |
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
bool IsPrime(long n) | |
{ | |
int c = 0; | |
for (long i = 1; i < n; i++) | |
{//loop up-till the number | |
if (n % i == 0)//check if its divisible by i | |
{ | |
c++; | |
if (c > 1) { return false; }//short-circuit.. | |
} //^^if it has more than one divisor it can't be prime |
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
long sum = 0; | |
long n = 2000000; | |
bool[] e = new bool[n];//by default they're all false | |
for (int i = 2; i < n; i++) | |
{ | |
e[i] = true;//set all numbers to true | |
} | |
//weed out the non primes by finding mutiples | |
for (int j = 2; j < n; j++) | |
{ |
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
Button btnLocation = (Button)findViewById(R.id.btnLocation); | |
btnLocation.setOnClickListener(new OnClickListener() { | |
public void onClick(View arg0) { | |
// Acquire a reference to the system Location Manager | |
LocationManager locationManager = | |
(LocationManager) AddressPOCActivity.this.getSystemService(Context.LOCATION_SERVICE); | |
// Define a listener that responds to location updates | |
LocationListener locationListener = new LocationListener() { | |
public void onLocationChanged(Location location) { | |
// Called when a new location is found by the network location provider. |
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 String GetAddress(String lat, String lon) | |
{ | |
Geocoder geocoder = new Geocoder(this, Locale.ENGLISH); | |
String ret = ""; | |
try { | |
List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(lat), Double.parseDouble(lon), 1); | |
if(addresses != null) { | |
Address returnedAddress = addresses.get(0); | |
StringBuilder strReturnedAddress = new StringBuilder("Address:\n"); | |
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) { |
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 void postData(String la, String lo) { | |
// Create a new HttpClient and Post Header | |
HttpClient httpclient = new DefaultHttpClient(); | |
HttpGet htget = new HttpGet("http://<your_app_url>/Home/Book/"+la+"/"+lo); | |
try { | |
// Execute HTTP Post Request | |
HttpResponse response = httpclient.execute(htget); | |
String resp = response.getStatusLine().toString(); | |
Toast.makeText(this, resp, 5000).show(); |
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
SELECT id,title, yr | |
FROM movie | |
WHERE title LIKE '%Star%Trek%' | |
ORDER BY yr ASC |