So I had a problem today where I needed to be able to tell if a JavaScript object was empty. I spent 10 minuets Googleing for a consice soluction then I went to jQuery util page on a whim and the answer was there.
http://api.jquery.com/jQuery.isEmptyObject/
With just one call the library will tell me if it has data. Thanks to the people that build such cool tools for me to use.
Showing posts with label lazy. Show all posts
Showing posts with label lazy. Show all posts
Wednesday, January 18, 2012
Thursday, August 4, 2011
My Rules for Development
- If you think you need a region you really need a new class.
- If you are using a for loop in c# there is something wrong with your code.
- If you are using a foreach fix you code so you don't need it.
- If you think you want to use exceptions to control flow stop now and go to your room and think about what damage you may do.
- If you don't write a unit test it's not done.
Wednesday, May 18, 2011
Some Fun With Linq.
A friend of mine was asking me how I search through dictionary that contain lists of objects with Linq. After I chatted with him for a bit. I realized I don't do that. I have one huge list that I parse out with linq. It makes my life easier. Here is a code example of what I would use.
public class section { public string Group { get; set; } public string Order { get; set; } public string Section { get; set; } public string Title { get; set; } } static void Main(string[] args) { var sec = new List<section>(); sec.Add(new section { Group = "1", Order = "1", Section = "1.1", Title = "one one" }); sec.Add(new section { Group = "1", Order = "3", Section = "1.3", Title = "one three" }); sec.Add(new section { Group = "1", Order = "2", Section = "1.2", Title = "one two" }); sec.Add(new section { Group = "2", Order = "1", Section = "2.1", Title = "two one" }); sec.Add(new section { Group = "2", Order = "2", Section = "2.2", Title = "two two" }); sec.Add(new section { Group = "3", Order = "1", Section = "3.1", Title = "three one" }); //creates a diction with all the sections in order grouped by group. var jmp = sec.OrderBy(j => j.Order).GroupBy(c => c.Group).ToDictionary(c => c.Key, d => d.ToList()); //gets one section form a section var wantedSection = sec.FirstOrDefault(c => c.Section == "2.2"); //return null if no iteem found //gets one section in the order you set in order var sectionOne = sec.Where(c => c.Group == "1").OrderBy(c => c.Order).ToList(); }
Wednesday, May 6, 2009
Some times you just have to rename files.
So I needed to rename a bunch of files. I needed to add the size of the file as a postfix. Same name just an adition of 16x16 which when doing it by hand is tedious. So this little script was created. You have to dump it into the same folder as the files you are working with, and you have to put the path in walkPath. I could have it pull the current directory from the os but that would take work.
import os
walkPath = r"some disk path"
for d in os.walk(walkPath):
dirpath, dirnames, filenames = d
for a in filenames:
if a.endswith(".py"):
pass
else:
print a
aSplit = a.split(".")
os.rename(a,aSplit[0]+"16x16."+aSplit[1])
Subscribe to:
Posts (Atom)