Search Results

Search found 2672 results on 107 pages for 'michael cereda'.

Page 55/107 | < Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >

  • Which Secure Software Development Practices do you Employ?

    - by Michael Howard-MSFT
    I work on a project known as the Security Development Lifecycle (SDL) project at Microsoft (http://microsoft.com/sdl) - in short it's a set of practices that must be used by product groups before they ship products to help improve security. Over the last couple of years, we have published a great deal of SDL documentation, as customers ask for more information about what we're doing. But what I'd like to know is: 1) What are you doing within your organization to help improve the security of your product? 2) What works? What doesn't work? 3) How did you get management to agree to this work? Thanks.

    Read the article

  • When did you know it was time to leave your job?

    - by Jeremy Michael Cantrell
    Every job has its ups and downs, but sometimes it just isn't worth it to stick around. I'm currently in one of the "down" points with my current job and debating whether or not to start testing the waters for something else. What are your experiences? How did you know it was time to leave? Do you ultimately feel like it was the right decision?

    Read the article

  • Backup Google Calendar programmatically: http://www.google.com/reader/subscriptions/export

    - by Michael
    I'm struggling with writing a python script that automatically grabs the zip fail containing all my google calendars and stores it (as a backup) on my harddisk. I'm using ClientLogin to get an authentication token (and successfully can obtain the token). Unfortunately, i'm unable to retrieve the file at https://www.google.com/calendar/exporticalzip It always asks me for the login credentials again by returning a login page as html (instead of the zip). Here's the critical code: post_data = post_data = urllib.urlencode({ 'auth': token, 'continue': zip_url}) request = urllib2.Request('https://www.google.com/calendar', post_data, header) try: f = urllib2.urlopen(request) result = f.read() except: print "Error" Anyone any ideas or done that before? Or an alternative idea how to backup all my calendars (automatically!)

    Read the article

  • Bind listbox in WPF with grouping

    - by Michael Stoll
    Hi, I've got a collection of ViewModels and want to bind a ListBox to them. Doing some investigation I found this. So my ViewModel look like this (Pseudo Code) interface IItemViewModel { string DisplayName { get; } } class AViewModel : IItemViewModel { string DisplayName { return "foo"; } } class BViewModel : IItemViewModel { string DisplayName { return "foo"; } } class ParentViewModel { IEnumerable<IItemViewModel> Items { get { return new IItemViewModel[] { new AItemViewModel(), new BItemViewModel() } } } } class GroupViewModel { static readonly GroupViewModel GroupA = new GroupViewModel(0); static readonly GroupViewModel GroupB = new GroupViewModel(1); int GroupIndex; GroupViewModel(int groupIndex) { this.GroupIndex = groupIndex; } string DisplayName { get { return "This is group " + GroupIndex.ToString(); } } } class ItemGroupTypeConverter : IValueConverter { object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is AItemViewModel) return GroupViewModel.GroupA; else return GroupViewModel.GroupB; } } And this XAML <UserControl.Resources> <vm:ItemsGroupTypeConverter x:Key="ItemsGroupTypeConverter "/> <CollectionViewSource x:Key="GroupedItems" Source="{Binding Items}"> <CollectionViewSource.GroupDescriptions> <PropertyGroupDescription Converter="{StaticResource ItemsGroupTypeConverter }"/> </CollectionViewSource.GroupDescriptions> </CollectionViewSource> </UserControl.Resources> <ListBox ItemsSource="{Binding Source={StaticResource GroupedItems}}"> <ListBox.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding DisplayName}" FontWeight="bold" /> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ListBox.GroupStyle> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding DisplayName}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> This works somehow, exept of the fact that the binding of the HeaderTemplate does not work. Anyhow I'd prefer omitting the TypeConverter and the CollectionViewSource. Isn't there a way to use a property of the ViewModel for Grouping? I know that in this sample scenario it would be easy to replace the GroupViewModel with a string an have it working, but that's not an option. So how can I bind the HeaderTemplate to the GroupViewModel?

    Read the article

  • bash - how to filter java exception info

    - by Michael Mao
    Hi all: We've got a multi-agent Java environment where different agent would most likely produce all sorts of exceptions thrown to stderr. Here is a sample taken from the huge exception log **java.security.AccessControlException: access denied (java.io.FilePermission ..\tournament\Driver\HotelRoomAnalyser.class read)** at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(Unknown Source) at java.io.File.length(Unknown Source) at emarket.client.EmarketSandbox$SandboxFileLoader.loadClassData(EmarketSandbox.java:218) at emarket.client.EmarketSandbox$SandboxFileLoader.loadClass(EmarketSandbox.java:199) at java.lang.ClassLoader.loadClass(Unknown Source) **java.security.AccessControlException: access denied (java.io.FilePermission ..\tournament\Driver\HotelRoomAnalyser.class read)** at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(Unknown Source) at java.io.File.length(Unknown Source) at emarket.client.EmarketSandbox$SandboxFileLoader.loadClassData(EmarketSandbox.java:218) at emarket.client.EmarketSandbox$SandboxFileLoader.loadClass(EmarketSandbox.java:199) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at MySmarterAgent.hotelRoomBookings(MySmarterAgent.java:108) fortunately all top-tier exceptions are denoted by no leading spaces, as wrapped by ** above. My concern is to get all of the top-tier exception name (delimited by colon :), together with the first line below which contains something like at emarket.client.EmarketSandbox$SandboxFileLoader.loadClassData(EmarketSandbox.java:218) Basically, something with padded style, starts with "at" and ends with ".java:108" So this info can be forwarded to the owner of that error-prone agent and let him/her fix it. My code in ~/.bashrc is incompleted now : alias startmatch='java -jar "emarket.jar" ../tournament 100'; function geterrors() { startmatch 2>"$1"; a=0; while read line do if true; then a=$(($a+1)); echo $a; fi; done } What it does now is to redirect all stderr to a text file specified by the first argument passed in, and after that, parse that text file line by line, if certain conditions returns true, echo only that line. And I am stuck with what to do inside the loop. Any suggestion is much appreciates, any hint is welcomed.

    Read the article

  • How to scrape Google SERP based on copyright year?

    - by Michael Mao
    Hi all: I know there must be ways to do this sort of things. I am not pro in RoR or Python, not even an expert in PHP. So my solution tends to be quite dumb: It uses a FireFox add-on called imarcos to scrape the target urls from Google SERP, and use PHP to store info into the database. At the very core of my workaround there lies a problem: How to specifically find target urls based on their copyright year? I mean, something like "copyright 1998-2006" in the footer is to be considered a target, but my search results are not 100% accurate. I used the following url to search : http://www.google.com.au/#hl=en&q=inurl:.com.au+intext:copyright+1995..2007+--2008+--2009&start=0&cad=b&fp=6a8119b094529f00 It reads : search for pages that have .com.au in URL and a copyright range from 1995 to 2007 exclude the year of 2008 or 2009. Starting position is 0, of course the offset can be changed. I've already done a dummy list and honestly I am not pleased with the result. That's mostly because I cannot find a way to restrict search terms in the exact order as they are entered into the search url. copyright can appear in anywhere on page and doesn't necessarily before the years, that's the current story. Is there a more clear way to sort out this? Oh, almost forgot to say the client doesn't wanna spent too much in this - I cannot persuade him simply buy some cool software, unfortunately. I hope there is a way to use clever Google search operators or similar things to go around this issue. Many thanks in advance!

    Read the article

  • .NET SortedDictionary But Sorted By Values

    - by Michael Covelli
    I need a data structure that acts like a SortedDictionary<int, double> but is sorted based on the values rather than the keys. I need it to take about 1-2 microseconds to add and remove items when we have about 3000 items in the dictionary. My first thought was simply to switch the keys and values in my code. This very nearly works. I can add and remove elements in about 1.2 microseconds in my testing by doing this. But the keys have to be unique in a SortedDictionary so that means that values in my inverse dictionary would have to be unique. And there are some cases where they may not be. Any ideas of something in the .NET libraries already that would work for me?

    Read the article

  • How do I start IRB console from a rake task?

    - by Michael Lang
    I'm trying to write a rake task that will set up an environment mirroring my project. task :environment do require 'rubygems' require 'sequel' # require 'my_projects_special_files' end task :foo => [:environment] do require 'irb' IRB.start end Leads to irb complaining that "foo" doesn't exist (the name of the task) 10:28:01:irb_test rake foo --trace (in /Users/mwlang/projects/personal/rake/irb_test) ** Invoke foo (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute foo rake aborted! No such file or directory - foo /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `open' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `new' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:92:in `new' /opt/local/lib/ruby/1.8/irb.rb:92:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:57:in `new' /opt/local/lib/ruby/1.8/irb.rb:57:in `start' /Users/mwlang/projects/personal/rake/irb_test/Rakefile:9

    Read the article

  • Can I convert a Stream object to a FileInfo object?

    - by Michael
    For the ExcelPackage constructor you need a FileInfo object. I rather use some kind of stream object(f.i. MemoryStream), because I don't need to save the file to the server itself, but expose it as a FileStream anyway to the user. I don't want to make files which I have to delete lateron from servers which are only there for generating purposes and never used again. Apart from that, otherwise I need also the necessary rights for the application/user on the directory/file on the server. So my question is then: How can I convert a stream object to a FileInfo object.

    Read the article

  • RegAsm for Class Library Used in VB6 Application

    - by michael.lukatchik
    To be short and to the point, I've built a C# class library that is both COM-Visible and Registered for COM Interop. I've compiled the library, which resulted in the generation of .dll and .tlb files. I have another machine that's running a VB6 application. So, I copied the .dll and .tlb files over to C:/Windows/system32 folder on the machine. I then registered those files using the following: C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm C:\Windows\system32\TestClass.dll /tlb:TestClass.tlb After the files were registered successfully, I added a project reference to the Test.tlb file from inside my VB6 app, then I tried to invoke a method in my new referenced class like so: Dim myObject As TestNamespace.TestClass Set myObject = New TestNamespace.TestClass MsgBox (myObject.TestMethod()) It doesn't work, and I receive a -2147024894 Automation Error. I've read that I shouldn't install the dll into a private folder like system32. I should either be registering in the GAC or I should be registering in another location using the "/codebase" option: C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm C:\TestClass.dll /tlb:TestClass.tlb /codebase Is there any reason I shouldn't be using system32? Past devs that have worked on this project have placed assembly files used by this VB6 project into system32 and there haven't seemed to be any issues. When I register my dll in the system32 location, I get the Automation Error. When I register my dll in another location (i.e. C:/), the method call into my class library from VB6 works as expected. What gives? I should mention that we will NOT be using the GAC to register any DLL's. That's just the way it is. Any help is appreciated. Mike

    Read the article

  • Improve drawingvisual render's speed

    - by Michael Hao
    I create my own FrameworkElement and override VisualChildrenCount{get;} and GetVisualChild(int index) by returning my own DrawingVisual collection instance.I have override OnRender . I will add 20-50 DrawingVisuals in this FrameworkElement ,every DrawingVisual will have 2000 line segments.The logic value of these points between 0 to 60000.when I zoom into 1:1 the FrameworkElement 's Height will be 60000, the rending time will be 15 minutes!! How do I improve the rending performance ?

    Read the article

  • Microsoft ACE OLEDB provider throws could not find installable ISAM exception

    - by Michael Stoll
    I'm trying to read Excel spreadsheets with a 64bit Process. Therefore I use the 64 bit Version of Micorosft Access Database Engine 2010. The following code var cs = @"Provider=Microsoft.ACE.OLEDB.12.0;" + @"Data Source=C:\test.xls;" + @"Extended Properties=""Excel 14.0;"""); con = new OleDbConnection(cs); con.Open(); throw an Exception: Could not find installable ISAM Using google I found a lot of questions about this exception. But they refer to JET and seem not apply to my problem. Any recommendations?

    Read the article

  • Grafting Scala 2.8 into a Netbeans NBAndroid Project...What steps am I missing?

    - by Michael Kohout
    Hi All; Due to Apple's recent T+C hijinks, I've become interested in developing for Android. Anyways, I'm trying to get a mixed-language Android 2.1 project going in Netbeans 6.8 (with the NBAndroid 0.10 plugin). The two languages being Java and Scala(2.8 head build). To give you a basic idea of what the app does right now, it's just a simple "Hello World" app. To get this to build, I've modified the projects's build.xml file: -- -injars ${scala-library}(!META-INF/MANIFEST.MF,!library.properties) -outjars "${build.classes.dir}/classes.min.jar" -libraryjars "${file.reference.android.jar}" -dontwarn -dontoptimize -dontobfuscate -keep public class * extends android.app.Activity -keep public class scala.xml.include.sax.Main** I've gotten the project so that it'll build, but it errors on startup in my Android Emulator(inside the emulator Android tells me my application has stopped unexpectedly). So my questions are: Does anyone see what I may be doing wrong? And is there any way to get access to the logs that the emulator must create? thanks Mike Kohout

    Read the article

  • JavaScript issues

    - by Michael
    My java scirpt is not working right. It is simple pre-vailidation form and I can not get the script to work. It is supposed to validate each field but I can not get it to validate past the first name. I stripped out all of the other garbage so the code would not be confusing Should be a copy paste to notepad. Little help please <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script language="JavaScript" type="text/javascript"> <!-- function validateForm(theForm) { var name = theForm.firstname.value; var name = theForm.lastname.value; var email = theForm.email.value; if (name == "") { alert("Please fill in your First Name."); theForm.firstname.focus(); return false; } if (name == "") { alert("Please fill in your Last Name."); theForm.lastname.focus(); return false; } if (email == "") { alert("Please fill in your email address."); theForm.email.focus(); return false; } return true; } //--> </script> if (!theForm.myCheckbox1.checked { alert("Please check the honor box."); return false; } </head> <body> </script> <fieldset> <legend>Fun in the Sun With JavaScirpt</legend> <ul> <form action="blah.cgi" method="post" onSubmit="return validateForm(this);"> First name: <input type="text" name="firstname"> <font color="#FF0000" size="1" face="Arial, Helvetica, sans-serif"><strong>*</strong></font> <br><br> Last name: <input type="text" name="lastname"> <font color="#FF0000" size="1" face="Arial, Helvetica, sans-serif"><strong>*</strong></font> <br><br> Email address: <input type="text" name="email"> <font color="#FF0000" size="1" face="Arial, Helvetica, sans-serif"><strong>*</strong></font> <br><br> Phone Number: <input type="text" name="phone"><br><br> <input type="submit" name="submit" value="Submit"> </form> <input type="checkbox" name="myCheckbox" value="someValue"><font color="#FF0000" size="1" face="Arial, Helvetica, sans-serif"><strong>*</strong></font> <P>By checking this Box you are confirming the data is accurate</p> <p>(* indicates a required field)</p> </body> </html>

    Read the article

  • Insert new relationship data in core data

    - by michael
    Hoping someone can shed some light on what I might be doing wrong here. Trying to add an "event" to a list of events, represented by a one to many (inverse) relationship: MyEvents <--- Event This is the code: MyEvents *myEvents = (MyEvents *)[NSEntityDescription insertNewObjectForEntityForName:@"MyEvents" inManagedObjectContext:context]; NSLog(@"MYEVENTS: %@", myEvents); NSLog(@"EVENT: %@", event); [myEvents addEventObject:event]; My context is fine, and both the myEvents and event print perfectly valid information. When I try to add the event that I have (which is passed into this view controller, having been retrieved from core data previously) with this code [myEvents addEventObject:event]; It falls over with *** -[NSComparisonPredicate evaluateWithObject:]: message sent to deallocated instance MyEvents and Event are just the default generated code. MyEvents contains only the relationship to event. Thanks.

    Read the article

  • TextRenderer.DrawText renders Arial differently on XP vs Vista

    - by Michael
    I have a c# application that does text rendering, something on par with a simple wysiwyg text editor. I'm using TextRenderer.DrawText to render the text to the screen and GetTextExtentPoint32 to measure text so I can position different font styles/sizes on the same line. In Vista this all works fine. In XP however, Arial renders differently, certain characters like 'o' and 'b' take up more width than in Vista. GetTextExtentPoint32 seems to be measuring the string as it would in Vista though, with the smaller widths. The end result is that every now and then a run of text will overlap the text preceding it because the preceding text gets measured as smaller than it actually is on the screen. Also, my text rendering code mimics ie's text rendering exactly (for simple formatting and english language only) and ie text rendering seems to be consistent between vista and xp - that's how I noticed the change in size of the different characters. Anyone have any ideas about what's going on? In short, TextRenderer.DrawText and GetTextExtentPoint32 don't match up in xp for Arial. DrawText seems to draw certain characters larger and/or smaller than it does in Vista but GetTextExtentPoint32 seems to be measuring the text as it would in Vista (which seems to match the text rendering in ie on both xp and vista). Hope that makes sense. Note: unfortunately TextRenderer.MeasureString isn't fast or accurate enough to meet my requirements. I tried using it and had to rip it out.

    Read the article

  • Can't update textbox in TinyMCE

    - by Michael Tot Korsgaard
    I'm using TinyMCE, the text area is replaced with a TextBox, but when I try to update the database with the new text from my textbox, it wont update. Can anyone help me? My code looks like this <%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="Test_TinyMCE._default" ValidateRequest="false" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <script src="JavaScript/tiny_mce/tiny_mce.js" type="text/javascript"></script> <script type="text/javascript"> tinyMCE.init({ // General options mode: "textareas", theme: "advanced", plugins: "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,pre view,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,no nbreaking,xhtmlxtras,template,wordcount,advlist,autosave", // Theme options theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft", theme_advanced_toolbar_location: "top", theme_advanced_toolbar_align: "left", theme_advanced_statusbar_location: "bottom", theme_advanced_resizing: true, // Example content CSS (should be your site CSS) // using false to ensure that the default browser settings are used for best Accessibility // ACCESSIBILITY SETTINGS content_css: false, // Use browser preferred colors for dialogs. browser_preferred_colors: true, detect_highcontrast: true, // Drop lists for link/image/media/template dialogs template_external_list_url: "lists/template_list.js", external_link_list_url: "lists/link_list.js", external_image_list_url: "lists/image_list.js", media_external_list_url: "lists/media_list.js", // Style formats style_formats: [ { title: 'Bold text', inline: 'b' }, { title: 'Red text', inline: 'span', styles: { color: '#ff0000'} }, { title: 'Red header', block: 'h1', styles: { color: '#ff0000'} }, { title: 'Example 1', inline: 'span', classes: 'example1' }, { title: 'Example 2', inline: 'span', classes: 'example2' }, { title: 'Table styles' }, { title: 'Table row 1', selector: 'tr', classes: 'tablerow1' } ], // Replace values for the template plugin template_replace_values: { username: "Some User", staffid: "991234" } }); </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox> <br /> <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Update</asp:LinkButton> </div> </asp:Content> My codebhind looks like this using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Test_TinyMCE { public partial class _default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { TextBox1.Text = Database.GetFirst().Text; } protected void LinkButton1_Click(object sender, EventArgs e) { Database.Update(Database.GetFirst().ID, TextBox1.Text); TextBox1.Text = Database.GetFirst().Text; } } } And finally the "Database" class im using looks like this using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Configuration; using System.Data.SqlClient; namespace Test_TinyMCE { public class Database { public int ID { get; set; } public string Text { get; set; } public static void Update(int ID, string Text) { SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["DatabaseConnection"]); connection.Open(); try { SqlCommand command = new SqlCommand("Update Text set Text=@text where ID=@id"); command.Connection = connection; command.Parameters.Add(new SqlParameter("id", ID)); command.Parameters.Add(new SqlParameter("text", Text)); command.ExecuteNonQuery(); } finally { connection.Close(); } } public static Database GetFirst() { SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["DatabaseConnection"]); connection.Open(); try { SqlCommand command = new SqlCommand("Select Top 1 ID, Text from Text order by ID asc"); command.Connection = connection; SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { Database item = new Database(); item.ID = reader.GetInt32(0); item.Text = reader.GetString(1); return item; } else { return null; } } finally { connection.Close(); } } } } I really hope that someone out there can help me

    Read the article

  • How can I get the following compiled on UVA?

    - by Michael Tsang
    Note the comment below. It cannot compiled on UVA because of a bug in GCC. #include <cstdio> #include <cstring> #include <cctype> #include <map> #include <stdexcept> class Board { public: bool read(FILE *); enum Colour {none, white, black}; Colour check() const; private: struct Index { size_t x; size_t y; Index &operator+=(const Index &) throw(std::range_error); Index operator+(const Index &) const throw(std::range_error); }; const static std::size_t size = 8; char data[size][size]; // Cannot be compiled on GCC 4.1.2 due to GCC bug 29993 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29993 typedef bool CheckFunction(Colour, const Index &) const; CheckFunction pawn, knight, bishop, king, rook; bool queen(const Colour c, const Index &location) const { return rook(c, location) || bishop(c, location); } static char get_king(Colour c) { return c == white ? 'k' : 'K'; } template<std::size_t n> bool check_consecutive(Colour c, const Index &location, const Index (&offsets)[n]) const { for(const Index *p = offsets; p != (&offsets)[1]; ++p) { try { Index target = location + *p; for(; data[target.x][target.y] == '.'; target += *p) { } if(data[target.x][target.y] == get_king(c)) return true; } catch(std::range_error &) { } } return false; } template<std::size_t n> bool check_distinct(Colour c, const Index &location, const Index (&offsets)[n]) const { for(const Index *p = offsets; p != (&offsets)[1]; ++p) { try { Index target = location + *p; if(data[target.x][target.y] == get_king(c)) return true; } catch(std::range_error &) { } } return false; } }; int main() { Board board; for(int d = 1; board.read(stdin); ++d) { Board::Colour c = board.check(); const char *sp; switch(c) { case Board::black: sp = "white"; break; case Board::white: sp = "black"; break; case Board::none: sp = "no"; break; } std::printf("Game #%d: %s king is in check.\n", d, sp); std::getchar(); // discard empty line } } bool Board::read(FILE *f) { static const char empty[] = "........" "........" "........" "........" "........" "........" "........" "........"; // 64 dots for(char (*p)[size] = data; p != (&data)[1]; ++p) { std::fread(*p, size, 1, f); std::fgetc(f); // discard new-line } return std::memcmp(empty, data, sizeof data); } Board::Colour Board::check() const { std::map<char, CheckFunction Board::*> fp; fp['P'] = &Board::pawn; fp['N'] = &Board::knight; fp['B'] = &Board::bishop; fp['Q'] = &Board::queen; fp['K'] = &Board::king; fp['R'] = &Board::rook; for(std::size_t i = 0; i != size; ++i) { for(std::size_t j = 0; j != size; ++j) { CheckFunction Board::* p = fp[std::toupper(data[i][j])]; if(p) { Colour ret; if(std::isupper(data[i][j])) ret = white; else ret = black; if((this->*p)(ret, (Index){i, j}/* C99 extension */)) return ret; } } } return none; } bool Board::pawn(const Colour c, const Index &location) const { const std::ptrdiff_t sh = c == white ? -1 : 1; const Index offsets[] = { {sh, 1}, {sh, -1} }; return check_distinct(c, location, offsets); } bool Board::knight(const Colour c, const Index &location) const { static const Index offsets[] = { {1, 2}, {2, 1}, {2, -1}, {1, -2}, {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2} }; return check_distinct(c, location, offsets); } bool Board::bishop(const Colour c, const Index &location) const { static const Index offsets[] = { {1, 1}, {1, -1}, {-1, -1}, {-1, 1} }; return check_consecutive(c, location, offsets); } bool Board::rook(const Colour c, const Index &location) const { static const Index offsets[] = { {1, 0}, {0, -1}, {0, 1}, {-1, 0} }; return check_consecutive(c, location, offsets); } bool Board::king(const Colour c, const Index &location) const { static const Index offsets[] = { {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1} }; return check_distinct(c, location, offsets); } Board::Index &Board::Index::operator+=(const Index &rhs) throw(std::range_error) { if(x + rhs.x >= size || y + rhs.y >= size) throw std::range_error("result is larger than size"); x += rhs.x; y += rhs.y; return *this; } Board::Index Board::Index::operator+(const Index &rhs) const throw(std::range_error) { Index ret = *this; return ret += rhs; }

    Read the article

  • GPL license and eiffel studio

    - by Michael Jenneson
    On https://www2.eiffel.com/download/download_info.aspx?id=eiffelstudio&info=false&mirrors=eiffelstudio you can download the IDE "eiffelstudio". They have GPL as their license but they also specify that "The GPL version is for the purpose of developing open-source software only! If you want to evaluate EiffelStudio for commercial software development, please download our Enterprise Evaluation Edition." However as far as i know this is directly against the gpl. Can they really specify such restrictions while adhering to the GPL?

    Read the article

  • Apache/PHP: error_log per Virtual Host?

    - by Michael Stum
    On one Linux Server running Apache and PHP 5, we got multiple Virtual Hosts with separate logfiles and everything. The only thing we cannot seem to separate between virtual hosts is the php error_log. Overriding this setting in the <Location> of the httpd.conf does not seem to do anything. Did I overlook something? Is there a way to have separate php error_logs for each Virtual Host?

    Read the article

  • Spring: Using "Lookup method injection" for my ThreadFactory looks not scalable.

    - by Michael Bavin
    Hi, We're building a ThreadFactory so everytime a singleton controller needs a new thread, i get a new instance everytime. Looking at Lookup method injection looks good but what if we have multiple threads. like: public abstract class ThreadManager { public abstract Thread createThreadDoA(); public abstract Thread createThreadDoB(); } and config: <bean id="threadManager" class="bla.ThreadManager" singleton="true"> <lookup-method name="createThreadA" bean="threadA" /> <lookup-method name="createThreadB" bean="threadB"/> </bean> <bean id="threadA" class="bla.ThreadA"> <bean id="threadB" class="bla.ThreadB"> and usage: threadManager.createThreadA(); I don't want to create an abstract "create" method for every new threadclass. Is it possible to make this generich like: threadManager.createThread(ThreadA.class); Thank you

    Read the article

< Previous Page | 51 52 53 54 55 56 57 58 59 60 61 62  | Next Page >