
roma★
Alisa U Zemlji Chuda
styofa doing anything

tannertan36

ellievsbear

Discoholic 🪩

Andulka
trying on a metaphor
Claire Keane

PR's Tumblrdome
dirt enthusiast

pixel skylines
PUT YOUR BEARD IN MY MOUTH
No title available
One Nice Bug Per Day

Kiana Khansmith

@theartofmadeline
AnasAbdin
I'd rather be in outer space 🛸
i don't do bad sauce passes

seen from Switzerland

seen from Switzerland
seen from Germany

seen from Malaysia
seen from United States
seen from United States

seen from United States

seen from Malaysia
seen from United States
seen from Italy

seen from Germany
seen from Poland
seen from United States

seen from Canada

seen from Malaysia

seen from Türkiye

seen from United States

seen from Germany
seen from United States

seen from Malaysia
@thread-hack
You can create a backup (.img) of your SD card to a network / USB drive while the card is inserted in your Raspberry PI!
make sure you have access to your network drive / usb drive; to see the devices type: sudo cat /etc/fstabs
create an img of the card currently in the PI to your network drive / USB drive using the dd command: sudo dd if=/dev/mmcblk0p2 of=/home/pi/networkdrive/my.img bs=1M (replace /dev/mmcblk0p2 with your own SD card and/home/pi/networkdrive/my.img with your own network drive / USB drive + image file name)
#math #doyourhomework
Math makes me feel even dumber than I already am.
Ugh.
I can’t even.
Every time I see a comment like this I can't help but think that the teacher is failing. Math has rules, teach the rules, understand the rules, follow the rules. Don't teach the equations; teach the rules.
Basic unit testing with .NET and Moq
I spent some more time looking at the test package that comes with Visual Studio 2010 and it looks pretty basic; mainly focusing on assertions. But what if I need to test more than assertions? That is where mocking comes into play. With mocking, you can test how your objects will interact with other objects. If I want to test my code against a Dao without actually hitting a database (which is what you want to do), then I would need to fake that connection and mock the Dao. Mocking the Dao will allow me to return any result that I would like from the operations based on the input.
For this quick example I will be using a third-party mocking library called Moq. You can find it on GitHub here.
I started by creating a very basic Dao:
using System; using System.Collections; namespace QuickTesting { /// /// Fake Dao /// public class DBClass { /// /// Local storage object /// private Hashtable hashTable = new Hashtable(); /// /// Public accessor of local storage object /// public Hashtable DataBase { get { return this.hashTable; } } public DBClass() { } /// /// Save the object in storage /// ///Object to save ///Success of storing public virtual bool Save(PlainObject po) { this.hashTable.Add(po.Id, po); return this.hashTable.ContainsKey(po.Id); } /// /// Update the object by replacement /// ///Object to update ///Success of update public virtual bool Update(PlainObject po) { this.hashTable[po.Id] = po; return this.hashTable.ContainsKey(po.Id); } /// /// Removes the object from storage /// ///The id of the object to remove /// Success of removal public virtual bool Delete(int Id) { this.hashTable.Remove(Id); return this.hashTable.ContainsKey(Id); } } }
Now I need an object to test against my quick Dao:
using System; namespace QuickTesting { /// /// Simple object to store values /// public class PlainObject { public int Id { get; set; } public string Name { get; set; } private DBClass dbClass; /// /// Constructor injection of the Dao object /// /// public PlainObject(DBClass dbClass) { if (dbClass == null) throw new ArgumentNullException("DBClass is null"); this.dbClass = dbClass; } /// /// Save the current object data to the database /// /// Success of save public bool SaveToDb() { return this.dbClass.Save(this); } /// /// Update the current object data in the database /// /// Success of update public bool UpdateToDb() { return this.dbClass.Update(this); } /// /// Remove the current object from the database /// /// Success of removal public bool RemoveFromDb() { return this.dbClass.Delete(this.Id); } } }
I am using constructor injection to give my PlainObject access to the Dao; now I need to test that is works correctly. The first test will test the DBClass and the PlainObject themselves to be sure that I don't have any problems before I try to mock the DBClass.
The second test will test the PlainObject against a mocked DBClass and let me know that I am getting the expected results and that I am exercising the correct code.
using System; using Moq; using Microsoft.VisualStudio.TestTools.UnitTesting; using QuickTesting; namespace QuickTestingTestProject { /// /// Quick test using mock objects /// [TestClass] public class QuickMockUnitTest { #region Mock Object Testing [TestMethod()] public void TestDBClass() { // Test both concrete classes DBClass dbClass = new DBClass(); PlainObject po = new PlainObject(dbClass); po.Id = 1; po.Name = "Homer"; // Verify that the object saved successfully Assert.IsTrue(po.SaveToDb()); // Verify that the object added is there and is the correct object Assert.AreEqual(dbClass.DataBase.Count, 1); Assert.ReferenceEquals(dbClass.DataBase[1], po); } [TestMethod()] public void MockTestOne() { var dbClassMock = new Mock(); // Create the classs to be tested PlainObject poHomer = new PlainObject(dbClassMock.Object); poHomer.Id = 1; poHomer.Name = "Homer"; PlainObject poMarge = new PlainObject(dbClassMock.Object); poMarge.Id = 2; poMarge.Name = "Marge"; // Mock the DBClass return values. Setting a different result based on // the object being passed into it. This helps to test different code paths // based on results. dbClassMock.Setup(db => db.Save(poMarge)).Returns(false); dbClassMock.Setup(db => db.Save(poHomer)).Returns(true); // The mock will return false no matter what for the poMarge Object Assert.IsFalse(poMarge.SaveToDb()); // The mock will return true no matter what for the poHomer Object Assert.IsTrue(poHomer.SaveToDb()); // Verify that save was called for all objects dbClassMock.Verify(v => v.Save(It.IsAny()), Times.Exactly(2)); // And verify that it was called for each object individually as well dbClassMock.Verify(v => v.Save(poMarge), Times.Once()); dbClassMock.Verify(v => v.Save(poHomer), Times.Once()); } #endregion } }
For the next post I will get more into mocking and show you just how powerful and easy it can be. Once again all of the code examples can be found on GitHub.
-t
Note: If you are unfamiliar with constructor injection you can read a decent description about it here.
Basic unit testing with .NET
I have recently moved back into the world of .NET development after spending about 5 years away from it. One of the many things that the developers at my previous employer did very well was test; specifically, unit testing. I have never done unit testing in .NET but I hope to bring some of the TDD concepts that I used prior to my new position.
Researching unit testing for .NET is a virtual bash-fest on the internet and there are quite a few opensource solutions but I would like to keep it limited to the Visual Studio environment for as long as I can. So let's see how far I can get before I have to result to a third-party solution
To start with, the unit testing features that are included in Visual Studio seem to be aimed at basic function testing so let's start there. All of the code will be available on GitHub if you care to follow along.
Here is a quick example:
public class MyCalc { public virtual int Add(int a, int b) { return a + b; } public virtual int Sub(int a, int b) { return a - b; } public virtual decimal Mul(int a, int b) { return a * b; } public virtual decimal Div(int a, int b) { return a / b; } }
And to test the basic functions:
private MyCalc myCalc = new MyCalc(); [TestMethod()] public void TestAdd() { Assert.AreEqual(this.myCalc.Add(1, 1), 2); } [TestMethod()] public void TestSub() { Assert.AreEqual(this.myCalc.Sub(3, 2), 1); } [TestMethod()] public void TestMul() { Assert.AreEqual(this.myCalc.Mul(3, 2), 6); } [TestMethod()] public void TestDiv() { Assert.AreEqual(this.myCalc.Div(3, 1), 3); } [TestMethod()] [ExpectedException(typeof(DivideByZeroException))] public void TestDivWithException() { Assert.AreEqual(this.myCalc.Div(3, 0), 1); }
Pretty basic but it's a start. Once I start diving into more difficult testing I will post it here. All of these code examples can be found here on GitHub.
-t
top of Lone Mountain... Done!
if you haven't read it, you should... soon.
brains over brawn, always.
scp examples
scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.
Examples:
Copy the file "foobar.txt" from a remote host to the local host
$ scp [email protected]:foobar.txt /some/local/directory
Copy the file "foobar.txt" from the local host to a remote host
$ scp foobar.txt [email protected]:/some/remote/directory
Copy the directory "foo" from the local host to a remote host's directory "bar"
$ scp -r foo [email protected]:/some/remote/directory/bar
Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"
$ scp [email protected]:/some/remote/directory/foobar.txt \[email protected]:/some/remote/directory/
Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host
$ scp foo.txt bar.txt [email protected]:~
Copy the file "foobar.txt" from the local host to a remote host using port 2264
$ scp -P 2264 foobar.txt [email protected]:/some/remote/directory
Copy multiple files from the remote host to your current directory on the local host
$ scp [email protected]:/some/remote/directory/\{a,b,c\} .
$ scp [email protected]:~/\{foo.txt,bar.txt\} .
Completely stolen from: http://www.hypexr.org/linux_scp_help.php
Ubuntu has ssh-copy-id Mac OSX does not.
Use this command to copy your local ssh public key to a remove server from a Mac.
cat ~/.ssh/id_rsa.pub | ssh user@machine "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
Great, I just got the WolframAlpha iPhone app, now I will be unproductive for the rest of the day...
Music
I can't believe there isn't a single solution that allows me to put all my music in one place and listen to it on any device I own.
iTunes:
Can't listen to it from work because it's located at my house.
Need to physically sync some devices.
Not enough physical space on devices to sync all music
Amazon:
Cloud player is a piece of shit.
Doesn't have an apple application.
Google:
See Amazon...
Stop Safari from opening previous tabs
Safari under Lion will re-open all of the previous tabs that were open when it was last closed. To prevent this:
defaults write com.apple.Safari ApplePersistenceIgnoreState YES
Fixing a Mercurial case-folding collision
abort: case-folding collision between WebContent/includes/page1.xhtml and WebContent/includes/Page1.xhtml
This usually means that there is a problem with a file having the same name but with different casing. The happens when a case-sensitive operating system changes the case of a file and then another user tries to update with a case-insensitive operating system.
FIX: update the project on a case-sensitive operating system by removing the version of the file not needed or you could do it the hard way: http://mercurial.selenic.com/wiki/FixingCaseCollisions