Search Results

Search found 45013 results on 1801 pages for 'example'.

Page 22/1801 | < Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >

  • Retactoring advanced has_many example

    - by atmorell
    Hello, My user model has three relations for the same message model, and is using raw SQL :/ Is there a better more rails way to achieve the same result? Could the foreign key be changed dynamically? e.g User.messages.sent (foreign key = author_id) and User.messages.received (foreign key = recipient ) I have been trying to move some of the logic into scopes in the message model, but the user.id is not available from the message model... Any thoughts? Table layout: create_table "messages", :force => true do |t| t.string "subject" t.text "body" t.datetime "created_at" t.datetime "updated_at" t.integer "author_id" t.integer "recipient_id" t.boolean "author_deleted", :default => false t.boolean "recipient_deleted", :default => false end This is my relations for my user model: has_many :messages_received, :foreign_key => "recipient_id", :class_name => "Message", :conditions => ['recipient_deleted = ?', false] has_many :messages_sent, :foreign_key => "author_id", :class_name => "Message", :conditions => ['author_deleted = ?', false] has_many :messages_deleted, :class_name => "Message", :finder_sql => 'SELECT * FROM Messages WHERE author_id = #{self.id} AND author_deleted = true OR recipient_id = #{self.id} AND recipient_deleted = true' Best regards. Asbjørn Morell

    Read the article

  • Collapsible controls in MFC (example included)

    - by John
    In the WindowsXP Control panel, you can see a nice collapsible panel control on the left: These are not just collapsible, but animated too. I wondered if these are any kind of control accessible to a developer, specifically in MFC? Or are they custom/bespoke functionality?

    Read the article

  • ruby, rails, railscasts example I messed up

    - by Sam
    If you saw the railscasts on nested forms this is the helper method to create links dynamically. However, after I upgraded to ruby 1.9.2 and rails 3 this doesn't work and I have now idea why. def link_to_add_fields(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :f => builder) end link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")")) end here is the javascript function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g") $(link).up().insert({ before: content.replace(regexp, new_id) }); } When I view source this is how the link is getting rendered: <p><a href="#" onclick="add_fields(this, &quot;dimensions&quot;, &quot;&quot;); return false;">Add Dimension</a></p> so &quot;&quot; is not the correct information to build a new template and something is going on with how the string for fields is getting set. such as fields= f.fields_for

    Read the article

  • Spring/Hibernate/Junit example of testing DAO against HSQLDB

    - by Ryan P.
    Hi guys, I'm working on trying to implement a JUnit test to check the functionality of a DAO. (The DAO will create/read a basic object/table relationship in HSQLDB). The trouble I'm having is the persistence of the DAO (for the non-test code) is being completed through an in-house solution using Spring/Hibernate, which eliminates the usual *.hbm.xml templates that most examples I have found contain. Beacuse of this, I'm having some trouble understanding how to setup a JUnit test to implement the DAO to create/read (just very basic funtionality) to an in-memory HSQLDB. I have found a few examples, but the usage of the in-house persistence means I can't extend some of the classes the examples show (I can't seem to get the application-context.xml setup properly). Can anyone suggest any projects/examples I could take a look at (or any documentation) to further my understanding of the best way to implement this test functionality? I feel like this should be really simple, but I keep running into problems implementing the examples I have found. Thanks in advance!

    Read the article

  • Git tutorial: Understanding git pull and branches (using a specific example repo)

    - by dreftymac
    Backround: Suppose I have the following Git URLs (hosted on github) http://github.com/mikl/drupal.git git://github.com/mikl/drupal.git (Git read-only) I am interested in having a local copy of this repository so I can pratice working with branches in git and see how my local working tree can change depending on which branch I am working with. Questions: To get started, I set up a local directory and do git clone git://github.com/mikl/drupal.git ... Will this clone all of the branches? Or will it only clone master? The web front-end for github gives me a "drop down" menu that allows me to switch branches ... Does changing this drop-down actually change which branch I will be grabbing when I run git clone? If I want a new copy of this repository on my local machine, but I am interested in only two branches of this repository and I want to ignore all the rest, what command do I use to ensure I clone only those two branches and nothing else (assume one of the branches is master)?

    Read the article

  • Simple typemap example in swig java

    - by celil
    I am trying to wrap a native C++ library using swig, and I am stuck at trying to convert time_t in C, to long in Java. I have successfully used swig with python, but so far I am unable to get the above typemap to work in Java. In python it looks like this %typemap(in) time_t { if (PyLong_Check($input)) $1 = (time_t) PyLong_AsLong($input); else if (PyInt_Check($input)) $1 = (time_t) PyInt_AsLong($input); else if (PyFloat_Check($input)) $1 = (time_t) PyFloat_AsDouble($input); else { PyErr_SetString(PyExc_TypeError,"Expected a large number"); return NULL; } } %typemap(out) time_t { $result = PyLong_FromLong((long)$1); } I guess the in map from Java to C would be: %typemap(in) time_t { $1 = (time_t) $input; } How would I complete the out map from C to Java? %typemap(out) time_t ??? Would I need typemaps like the ones below? %typemap(jni) %typemap(jtype) %typemap(jstype) I need this in order to wrap C functions like this: time_t manipulate_time (time_t dt);

    Read the article

  • Can I get an example please?

    - by Doug
    $starcraft = array( "drone" => array( "cost" => "6_0-", "gas" => "192", "minerals" => "33", "attack" => "123", ) "zealot" => array( "cost" => "5_0-", "gas" => "112", "minerals" => "21", "attack" => "321", ) ) I'm playing with oop and I want to display the information in this array using a class, but I don't know how to construct the class to display it. This is what I have so far, and I don't know where to go from here. Am I supposed to use setters and getters? class gamesInfo($game) { $unitname; $cost; $gas; $minerals; $attack; }

    Read the article

  • Is this an example of LINQ-to-SQL?

    - by Edward Tanguay
    I made a little WPF application with a SQL CE database. I built the following code with LINQ to get data out of the database, which was surprisingly easy. So I thought "this must be LINQ-to-SQL". Then I did "add item" and added a "LINQ-to-SQL classes" .dbml file, dragged my table onto the Object Relational Designer but it said, "The selected object uses an unsupported data provider." So then I questioned whether or not the following code actually is LINQ-to-SQL, since it indeed allows me to access data from my SQL CE database file, yet officially "LINQ-to-SQL" seems to be unsupported for SQL CE. So is the following "LINQ-to-SQL" or not? using System.Linq; using System.Data.Linq; using System.Data.Linq.Mapping; using System.Windows; namespace TestLinq22 { public partial class Window1 : Window { public Window1() { InitializeComponent(); MainDB db = new MainDB(@"Data Source=App_Data\Main.sdf"); var customers = from c in db.Customers select new {c.FirstName, c.LastName}; TheListBox.ItemsSource = customers; } } [Database(Name = "MainDB")] public class MainDB : DataContext { public MainDB(string connection) : base(connection) { } public Table<Customers> Customers; } [Table(Name = "Customers")] public class Customers { [Column(DbType = "varchar(100)")] public string FirstName; [Column(DbType = "varchar(100)")] public string LastName; } }

    Read the article

  • Compressibility Example

    - by user285726
    From my algorithms textbook: The annual county horse race is bringing in three thoroughbreds who have never competed against one another. Excited, you study their past 200 races and summarize these as prob- ability distributions over four outcomes: first (“first place”), second, third, and other. Outcome Aurora Whirlwind Phantasm 0.15 0.30 0.20 first 0.10 0.05 0.30 second 0.70 0.25 0.30 third 0.05 0.40 0.20 other Which horse is the most predictable? One quantitative approach to this question is to look at compressibility. Write down the history of each horse as a string of 200 values (first, second, third, other). The total number of bits needed to encode these track- record strings can then be computed using Huffman’s algorithm. This works out to 290 bits for Aurora, 380 for Whirlwind, and 420 for Phantasm (check it!). Aurora has the shortest encoding and is therefore in a strong sense the most predictable. How did they get 420 for Phantasm? I keep getting 400 bytes, as so: Combine first, other = 0.4, combine second, third = 0.6. End up with 2 bits encoding each position. Is there something I've misunderstood about the Huffman encoding algorithm? Textbook available here: http://www.cs.berkeley.edu/~vazirani/algorithms.html (page 156).

    Read the article

  • Dynamic typed language example using ANTLR

    - by wvd
    Hey all, I'm looking for some ANTLR examples, I tried googling a bit but I found certain things which didn't fit my requirments. I found the Mantra project, but it's statically typed and is 'too' big for me at this moment, then I found 'pie' as interpreter, which is dynamically typed, which what I want, but it uses a syntax-directed interpreter. I'm looking for a pretty small language which is dynamically typed and uses AST's if possible. It doesn't need to be advanced, if it would have classes I would already be very happy. Thanks, William van Doorn

    Read the article

  • clang parser pass example

    - by anon
    Hi! Can anyone paste sample code for a clang extra preprocessor pass where it: takes every variable named "foo", and renames it "bar", thus making the following code legal: int main() { int foo; bar = 5; } ? Thanks! [Aside: what I'm trying to do is write my own macro system for clang. Doing the above will let me inject at the right level to do my rewrites.] Thanks!

    Read the article

  • Simple NSTableView bindings example

    - by sirjorj
    I am trying to populate a 2-column NSVTableView via bindings, but the data is not showing up in the table. In XCode: I have a NSMutableArray in my AppDelegate that will hold the data, as well as the corresponding @property and @synthesize. On an event, I call [removeAllObjects] on the NSMutableArray and repopulate it with some NSDictionary objects. Each dictionary contains 2 KVP's: a NAME and a VALUE. In IB: I added an NSArrayController and bound it's Content Array to my AppDelegate and set the ModelKeyPath to the name of the NSMutableArray in the AppDelegate. On the NSTableView, I bound the Content to the ArrayController. ControllerKey = "arrangedObjects", ModelKeyPath = empty. For each of the two columns, I bound the Value to the AppController and set the ModelKeyPaths to NAME and VALUE respectively. ControllerKey = "ArrangedObjects". I have tried several other things, such as using an NSArray in the app delegate and making a new one every time I need to update the values. There must be some tiny little thing I am forgetting. What is it? jorj

    Read the article

  • Ruby PTY.spawn is Hanging - How to fill out Email and Password in simple example

    - by viatropos
    After asking this question, it looks like I need to use Ruby's PTY Module, of which there is no documentation. I have written this code to try to push content to Google App Engine because the python command sometimes asks me for my username and password. But when I run this code, it just hangs. cmd = "appcfg.py update cdn" PTY.spawn("#{cmd} 2>&1") do | input, output, pid | begin input.expect("Email:") do output.write("#{credentials[:username]}\n") end input.expect("Password:") do output.write("#{credentials[:password]}\n") end rescue Exception => e puts "GAE Error..." end end What am I missing here? How can I get this to work?

    Read the article

  • trending topics example for a rails app

    - by Gautam
    Hi, I am new to ruby on rails. I want to build an RSS feed aggregator. How do I find out the trending topics from the stream of data[titles] from various RSS feeds. Could you help me how to achieve this?? Looking forward for your help Thanks in advance Gautam

    Read the article

  • Example open source client-server code projects

    - by Ricket
    I'm still trying to determine an answer to my question from a few minutes ago, "Should client-server code be written in one 'project' or two?" and I think it would benefit me to see how other projects organize their code (and hopefully deduce the pros and cons of why they chose to do it that way). What are some open source client-server projects which might be best to look at and mimic their code organization style? Java is preferred but not required.

    Read the article

  • Delphi 7: ADO, need basic coding example

    - by mawg
    I am a complete n00b here. Can someone please post some Delphi code to create a database add a simple table close the database then, later open a database read each table read each field of a given table perform a simple search Sorry to be so clueless. I did google, but didn't find a useful tutorial ...

    Read the article

  • Example of ==, equals and hashcode in java

    - by Abhishek Jain
    Given this: String s1= new String("abc"); String s2= new String("abc"); String s3 ="abc"; System.out.println(s1==s3); System.out.println(s1==s2); System.out.println(s1.equals(s2)); System.out.println(s1.equals(s3)); System.out.println(s1.hashCode()); System.out.println(s2.hashCode()); System.out.println(s3.hashCode()); Output is: false false true true 96354 96354 96354 Here == is giving false for each object but hashcode for each String object is same. Why is it so?

    Read the article

  • service.close() vs. service.abort() - WCF example

    - by Larry Watanabe
    In one of the WCF tutorials, I saw the followign sample code: Dim service as ...(a WCF service ) try .. service.close() catch ex as Exception() ... service.abort() end try Is this the correct way to ensure that resources (i.e. connections) are released even under error conditions? Thanks for the answers guys! I upvoted you all.

    Read the article

  • C++ simple logging class with UTF-8 output [code example]

    - by Andrew
    Hello everyone, I was working on one of my academic projects and for the first time I needed pure C++ without GUI. After googling for a while, I did not find any simple and easy to use implementation for logging and created my own. This is a simple implementation with iostreams that logs messages to screen and to the file simultaneously. I was thinking of using templates but then I realized that I do not expect any changes and removed that. It is modified std::wostream with two added modifiers: 1. TimeStamp - prints time-stamp 2. LogMode(LogModes) - switches output: file only, screen only, file+screen. *Boost::utf8_codecvt_facet* is used for UTF-8 output. // ############################################################################ // # Name: MyLog.h # // # Purpose: Logging Class Header # // # Author: Andrew Drach # // # Modified by: <somebody> # // # Created: 03/21/10 # // # SVN-ID: $Id$ # // # Copyright: (c) 2010 Andrew Drach # // # Licence: <license> # // ############################################################################ #ifndef INCLUDED_MYLOG_H #define INCLUDED_MYLOG_H // headers -------------------------------------------------------------------- #include <string> #include <iostream> #include <fstream> #include <exception> #include <boost/program_options/detail/utf8_codecvt_facet.hpp> using namespace std; // definitions ---------------------------------------------------------------- // ---------------------------------------------------------------------------- // DblBuf class // Splits up output stream into two // Inspired by http://wordaligned.org/articles/cpp-streambufs // ---------------------------------------------------------------------------- class DblBuf : public wstreambuf { private: // private member declarations DblBuf(); wstreambuf *bf1; wstreambuf *bf2; virtual int_type overflow(int_type ch) { int_type eof = traits_type::eof(); int_type not_eof = !eof; if ( traits_type::eq_int_type(ch,eof) ) return not_eof; else { char_type ch1 = traits_type::to_char_type(ch); int_type r1( bf1on ? bf1->sputc(ch1) : not_eof ); int_type r2( bf2on ? bf2->sputc(ch1) : not_eof ); return (traits_type::eq_int_type(r1,eof) || traits_type::eq_int_type(r2,eof) ) ? eof : ch; } } virtual int sync() { int r1( bf1on ? bf1->pubsync() : NULL ); int r2( bf2on ? bf2->pubsync() : NULL ); return (r1 == 0 && r2 == 0) ? 0 : -1; } public: // public member declarations explicit DblBuf(wstreambuf *bf1, wstreambuf *bf2) : bf1(bf1), bf2(bf2) { if (bf1) bf1on = true; else bf1on = false; if (bf2) bf2on = true; else bf2on = false; } bool bf1on; bool bf2on; }; // ---------------------------------------------------------------------------- // logstream class // Wrapper for a standard wostream with access to modified buffer // ---------------------------------------------------------------------------- class logstream : public wostream { private: // private member declarations logstream(); public: // public member declarations DblBuf *buf; explicit logstream(wstreambuf *StrBuf, bool isStd = false) : wostream(StrBuf, isStd), buf((DblBuf*)StrBuf) {} }; // ---------------------------------------------------------------------------- // Logging mode Class // ---------------------------------------------------------------------------- enum LogModes{LogToFile=1, LogToScreen, LogToBoth}; class LogMode { private: // private member declarations LogMode(); short mode; public: // public member declarations LogMode(short mode1) : mode(mode1) {} logstream& operator()(logstream &stream1) { switch(mode) { case LogToFile: stream1.buf->bf1on = true; stream1.buf->bf2on = false; break; case LogToScreen: stream1.buf->bf1on = false; stream1.buf->bf2on = true; break; case LogToBoth: stream1.buf->bf1on = true; stream1.buf->bf2on = true; } return stream1; } }; logstream& operator<<(logstream &out, LogMode mode) { return mode(out); } wostream& TimeStamp1(wostream &out1) { time_t time1; struct tm timeinfo; wchar_t timestr[512]; // Get current time and convert it to a string time(&time1); localtime_s (&timeinfo, &time1); wcsftime(timestr, 512,L"[%Y-%b-%d %H:%M:%S %p] ",&timeinfo); return out1 << timestr; } // ---------------------------------------------------------------------------- // MyLog class // Logs events to both file and screen // ---------------------------------------------------------------------------- class MyLog { private: // private member declarations MyLog(); auto_ptr<DblBuf> buf; string mErrorMsg1; string mErrorMsg2; string mErrorMsg3; string mErrorMsg4; public: // public member declarations explicit MyLog(string FileName1, wostream *ScrLog1, locale utf8locale1); ~MyLog(); void NewEvent(wstring str1, bool TimeStamp = true); string FileName; wostream *ScrLog; wofstream File; auto_ptr<logstream> Log; locale utf8locale; }; // ---------------------------------------------------------------------------- // MyLog constructor // ---------------------------------------------------------------------------- MyLog::MyLog(string FileName1, wostream *ScrLog1, locale utf8locale1) : // ctors mErrorMsg1("Failed to open file for application logging! []"), mErrorMsg2("Failed to write BOM! []"), mErrorMsg3("Failed to write to file! []"), mErrorMsg4("Failed to close file! []"), FileName(FileName1), ScrLog(ScrLog1), utf8locale(utf8locale1), File(FileName1.c_str()) { // Adjust error strings mErrorMsg1.insert(mErrorMsg1.length()-1,FileName1); mErrorMsg2.insert(mErrorMsg2.length()-1,FileName1); mErrorMsg3.insert(mErrorMsg3.length()-1,FileName1); mErrorMsg4.insert(mErrorMsg4.length()-1,FileName1); // check for file open errors if ( !File ) throw ofstream::failure(mErrorMsg1); // write UTF-8 BOM File << wchar_t(0xEF) << wchar_t(0xBB) << wchar_t(0xBF); // switch locale to UTF-8 File.imbue(utf8locale); // check for write errors if ( File.bad() ) throw ofstream::failure(mErrorMsg2); buf.reset( new DblBuf(File.rdbuf(),ScrLog->rdbuf()) ); Log.reset( new logstream(&*buf) ); } // ---------------------------------------------------------------------------- // MyLog destructor // ---------------------------------------------------------------------------- MyLog::~MyLog() { *Log << TimeStamp1 << "Log finished." << endl; // clean up objects Log.reset(); buf.reset(); File.close(); // check for file close errors if ( File.bad() ) throw ofstream::failure(mErrorMsg4); } //--------------------------------------------------------------------------- #endif // INCLUDED_MYLOG_H Tested on MSVC 2008, boost 1.42. I do not know if this is the right place to share it. Hope it helps anybody. Feel free to make it better.

    Read the article

  • Best ways to copyright protect your work for example Myows

    - by Saif Bechan
    Recently I have read about Myows, they say its: "The universal copyright management and protection app for smart creatives" It is used to protect your application from copyrights and more. Do you think this will be a good idea for large application, or are there better ways to achieve such a thing. url: Myows Update Referencing: http://stackoverflow.com/questions/2618015/has-anyone-tried-myows-to-copyright-protect-your-work/2618628#2618628 Wow there is no better person to have answered this question like the creator himself. Currently I am working on a large web application which is in late testing phase. Because of the complexity of the app there are not many versions of it online so copyright will be a huge issue for me as much of the code is in JavaScript and is easy copyable. I was glad to see that there is some company out there that provide such services, and naturally I wanted to know if there were people using it. I did not know that this type of concept was so 'new'. There were some nice points made in the answer, and I think it will be a good service for people like me. In the next couple of weeks I will be looking further into the subject and start uploading my code and see how it will works out. I will leave this question up because I do want some more suggestions on this topic.

    Read the article

  • Example compilers

    - by saf
    I'm searching for the source code of a compiler capable of creating Win32 programs from an input program in a programming language (It doesn't matter which, maybe the simpler the better) Yet I can't find anything right for me and huge compilers like GCC make me extremely confused as they have so many features that I don't know where to start. Is there an OpenSource Win32 micro-compiler for some programming language out there I could take a look at?

    Read the article

< Previous Page | 18 19 20 21 22 23 24 25 26 27 28 29  | Next Page >