r/programminganswers • • Oct 10 '14

Meta [META PROGRAMMINGANSWERS] Why does this subreddit entirely break Reddit Enhancement Suite?

0 Upvotes

See title.


r/programminganswers • • Sep 07 '14

Closed Post [Tcl] Tcl IRCD - help wanted

0 Upvotes

There is currently no testnet, but oh well. I'd like to know if there's anyone who would like to help me add linking support to https://github.com/asterIRC/ircd-thc which is a Tcl ircd which supports +qaohv and not much else (I believe bans work).


r/programminganswers • • Jun 01 '15

Tkinter: How do I change the fill of a canvas object

1 Upvotes

I am trying to change the fill color of a canvas rectangle based on the color it is currently> If the fill="yellow", itemconfig fill="blue" but if it's "red" then change it to "white". I think I need to use cget but cannot make it work. Please help!


r/programminganswers • • May 16 '14

How do I retrieve the component used at a specific cell in a JTable?

1 Upvotes

I've created a JTable whose columns contain a variety of different components. The last five columns either contain nothing (a DefaultTableCellRenderer with no value) or a JRadioButton using a custom renderer and editor. My goal is to add the buttons to a ButtonGroup. I am using the following piece of code that I wrote:

protected void setButtonGroups() { buttonGroups = new ArrayList(); for (int i = 0; i

getComponentAt() keeps returning null regardless of what is contained in the cell, whether it be a JCheckBox, JRadioButton, JComboBox... everything is returned as null.

Is there an alternative way to get the cell's component? Or is there a way for me to get this to work? Thank you!

by user3280809


r/programminganswers • • May 16 '14

LNK2001 Only some inline functions unresolved?

1 Upvotes

This has been a problem for some time now but I haven't found any real solution. Basically, I have several classes that have roughly 10-20 inline functions each that just retrieve simple information from the class. All of them are one line functions and all of them do the same thing with different parameters. Most of the time they compile fine, but every once in awhile the compiler will say something is unresolved in the middle of functions with the same sort of definition.

For example, here's a part of my class' header definition which has public scope:

... inline uint32_t debug_offset(); inline uint32_t debug_load_addr(); inline uint32_t dol_offset(); inline uint32_t fst_offset(); inline uint32_t fst_size(); inline uint32_t fst_max_size(); ...

And here are their definitions:

... uint32_t Header::debug_offset() { return VectorData::read(ref(header), Offset::DebugOffset); } uint32_t Header::debug_load_addr() { return VectorData::read(ref(header), Offset::DebugAddress); } uint32_t Header::dol_offset() { return VectorData::read(ref(header), Offset::DOLOffset); } uint32_t Header::fst_offset() { return VectorData::read(ref(header), Offset::FSTOffset); } uint32_t Header::fst_size() { return VectorData::read(ref(header), Offset::FSTSize); } uint32_t Header::fst_max_size() { return VectorData::read(ref(header), Offset::FSTMaxSize); } ...

All of these will compile fine along with the other 20 or so similar functions, except for fst_offset which throws this error:

Error 1 error LNK2001: unresolved external symbol "public: unsigned int __thiscall Header::fst_offset(void)" (?fst_offset@Header@@QAEIXZ)

This has happened to several other classes as well. I'll have one or two out of all the inline functions throw this error when all the others are fine. The simple fix is to just take the functions that throw the error and put the body in the header, but that changes the layout of the project and makes it not consistent.

Is this a compiler error? Am I doing something different and I don't know it? I want to avoid defining some functions in headers and others in source files if at all possible.

by ozdrgnaDiies


r/programminganswers • • May 16 '14

SED in shell scripting, not working as expected

1 Upvotes

I am writing a script which will read some data from txt files and then generate an html file with the data from the other files. I have lines starting with # which I have to skip - this is done. But the problem is that when I read the files I have to skip the words , , and .

I don't have problem with excluding and , I am using:

cat ~/linux/footer.txt | sed 's///g' > ~/linux/footer_temp.txt

but the problem is with and ...

Any suggestions what can I use and how to make it work?

Thanks

by Berchev


r/programminganswers • • May 17 '14

Png file in a TImage Component Dephi7 Is there a way to use?

1 Upvotes

Png file in a TImage Component Dephi7 can not use. Png file in a TImage Component Dephi7 Is there a way to use? Thank you respond.

by bestdragon


r/programminganswers • • May 17 '14

Prolog Chaining winners?

1 Upvotes

I'm trying to compare two people and from those 2 people if the person had played someone before and won then lost to the newer person then that person technically is above from everyone else.

For example, It's set up like this:

Example of how it's set up: winner(won, lost).

winner(john, jacob). winner(mike, john). winner(scott, mike). winner(matt, scott). winner(X, Z) :- winner(X, Y), winner(Y, Z).

If I call: winner(matt, mike). It'll return true since matt beat scott which means he also beats mike since mike lost to scott.

I have it only querying on tier down with that current rule, how would I go about querying through unlimited tiers? I'm confused on how to approach this.

by user3646479


r/programminganswers • • May 17 '14

Prolog procedure

1 Upvotes

I will begin by saying that I am very new to Prolog, and that it is still very hard for me to come up with a solution and not think it in a procedural or a functional way.

The context of the problem is as follows: I have to move in four directions starting from the initial position (0,0). When I move up I update my position to (0,1), down to (0, -1), left to (-1,0) and right to (1, 0). At some point I have to go back to my initial position.

I have solved the problem by memorizing all the moves that I do to a certain point and then do the reverse. So if the moves I did were down, left I just go up, west. The solution works, but it is very inefficient and dumb.

So the thing I want to do is to make a procedure that takes the current position (X,Y) and evaluates to one of the four moves if by updating the position I am closer to (0,0).

I have tried to write some code, but the truth is that I don't really know how to think the problem in Prolog. Can someone give me some hints how I can solve it ? Thank you!

by Roxana Ciobanu


r/programminganswers • • May 17 '14

Upgraded saved packages with bower and npm to latest version

1 Upvotes

So not sure if it's possible and not finding it in docs but I may be missing it.

I use bower and npm and save the package version to their respective json file.

For example I fetch jquery and save that version:

bower install jquery --save

Now down the line I want to try the latest jquery version. What I do currently is delete the jquery entry from components.json and redo the above line. Is there a way to do it all in one go? (I don't mean concat commands - just something built in I may have overlooked).

by Yashua


r/programminganswers • • May 17 '14

Fast math parsing library for iOS

1 Upvotes

I'm looking for a recommendation for a fast math parsing library. I don't actually care about how fast it actually parses the expression, but how quickly it can evaluate with different variables.

I've looked at a few options so far.

DDMathParser: This was my first choice, and it was pretty great to work with, but it's too slow. Every call to evaluate parses the expression from scratch.

GCMathParser: This one was a little ugly. I appreciate its speed, but I found it impossible to retrieve a list of variables used in the expression.

I was going to resort to using DDMathParser's tokenizer and parser to get variables and then use GCMathParser to do the actual parsing, but I figured there must be a better solution out there.

I'd love to hear about anything used in practice. I'm also happy to write my own Obj-C wrapper around a nice C/C++ framework.

by mxweas


r/programminganswers • • May 17 '14

Forward taps from UITextView to UITableViewCell

1 Upvotes

I've got a UITextView in a uitableviewcell that I am using exclusively to allow copy/paste of the contents. However, single taps to the textView are not getting forwarded to the tableViewCell.

Is there any way around this?

by Sean Danzeiser


r/programminganswers • • May 17 '14

Ajax POST request, change css on button if json.object equals to true

1 Upvotes

I have this jQuery code:

$(document).ready(function() { $('#quiz-options button').click(function() { // Ajax post request $.ajax({ type: "POST", url: "/quiz/check/", data: { 'id' : $(this).val(), }, success: success, dataType: 'json' }); }); }); function success(data, status, xmp){ // Question is correct if(data.correct == true){ $('#quiz-options button').val(data.id).addClass("correct"); } // Question is wrong else { $(this).addClass("error"); }}

My problem is that if I use $('#quiz-options button').val(data.id).addClass("correct"); this line the css is added to every button, and when I try with the secound way with $(this) is do not chanage anything.

I think the problem is that the success function dont have access to $this, however, how do I pass it down to the success function so that I can use it to change the css?

Many thanks.

by Thomas Holden


r/programminganswers • • May 17 '14

MySQL Query to return unique values based on distinct on 3 fields

1 Upvotes

I am trying to search 1 table in the database and count the number of unique records where 3 fields do not match. I have the below but it doesn't work at all. I am an SQL noob so any help really is appreciated!

This is what I have so far

 php SELECT COUNT(*) FROM ( SELECT DISTINCT field1, field2, field3 FROM table1); $result = $query; $row = mysql_fetch_array($result); echo $row; ?>

Thanks for any help!

by 5ummer5


r/programminganswers • • May 17 '14

Shell script not working as expected

1 Upvotes

I have issues with part of my shell script

if [ -e ~/linux/content.txt ] then cat ~/linux/content.txt | sed -re 's///g' > ~/linux/content_temp.txt rm content.txt cat ~/linux/content_temp.txt | sed -re 's|||g' > ~/linux/content.txt rm content_temp.txt cat ~/linux/content.txt | sed -re 's///g' > ~/linux/content_temp.txt rm content.txt cat ~/linux/content_temp.txt | sed -re 's|||g' > ~/linux/content.txt rm content_temp.txt CONTENT=$(grep -v "^[[:blank:]]*#" ~/linux/content.txt) echo $CONTENT else echo "Content file not found" fi

It just deletes the file and stops... It has to check for the words delete them and then at the end I have to have a clear content.txt file but I don't. Could you let me know why?

by Berchev


r/programminganswers • • May 17 '14

c# async httpclient operation

1 Upvotes

I am trying to design a browser that will fetch site updates programmatically. I am trying to do this with async/await methods but when I try and run the program it seems to just hang on response.Wait();. not sure why or whats happening.

public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); var urls = sourceUrls(); Task response = login(urls[0]); response.Wait(); Console.Write( "Complete" ); } private List sourceUrls() { var urls = new List(); urls.Add(new Site("http://yahoo.com", "test", "test")); return urls; } }

browser class::

static public class Browser { private static CookieContainer cc = new CookieContainer(); private static HttpClientHandler handler = new HttpClientHandler(); public static HttpClient browser = new HttpClient(handler); static Browser() { handler.CookieContainer = cc; } static public async Task login(Site site) { var _postData = new Dictionary { {"test", "test"} }; FormUrlEncodedContent postData = new FormUrlEncodedContent(_postData); HttpResponseMessage response = await browser.PostAsync(site.url, postData); return response; } }

Also, for my intended purposes, is it ok to make browser a static function, or does that not make sense? Sorry for the questions, new to c#

by Yevgeny Yurgenson


r/programminganswers • • May 17 '14

Nested increasing foreach loop

1 Upvotes

What is the idiomatic way to get something like that?

((fn [coll] (function-body)) [:a :b :c :d]) -> [[:a :b][:a :c][:a :d][:b :c][:b :d][:c :d]]

I can only do this in this way.

#(for [i (range (count %)) j (range (inc i) (count %))] [(nth % i) (nth % j)])

But this is ugly, and at bigger collections very slow. I would like to avoid a loop/recur

by HuxleySource


r/programminganswers • • May 17 '14

Bits exchange trouble C#

1 Upvotes

I have to write a program that takes bits 3,4,5 and puts them into the place of bits 24,25,26 and then it takes bits 24,25,26 (from the original number) and puts them in the place of bits 3,4,5. The code that I wrote succesfuly transfers 3,4,5 to 24,25,26 but I can't understand why it's not working the other way around.. I also want to ask if there is an easier way to do this..

static void Main() { Console.Write("Please input your number: "); int num = Convert.ToInt32(Console.ReadLine()); int mask = 0; int bit = 0; int p = 0; int numP = 0; //take bit 3,4,5 and put them in the place of 24,25,26 for (int i = 0; i > p; bit = numP & 1; if (bit == 1) { mask = 1 > p; bit = numP & 1; if (bit == 1) { mask = 1

by Darkbound


r/programminganswers • • May 17 '14

Can you use ng-switch and ng-if together?

1 Upvotes

I was trying to use both the angular ng-switch and ng-if directives together, but it doesn't seem to be working. What I was doing was:

I'm just wondering if that is possible or if there is an alternative way to switch those partials around based on some condition in the $scope?

by This 0ne Pr0grammer


r/programminganswers • • May 17 '14

mvvmcross: How to use enum values as ItemsSource

1 Upvotes

I have the following in my model:

public class Equipment { public enum Type { Detector, VegetationClearance, Removal, Engaging } }

And in the view model:

 private Equipment.Type _equipmentType; public Equipment.Type EquipmentType { get { return _equipmentType; } set { _equipmentType = value; RaisePropertyChanged(() => EquipmentType); } }

And I want to use the values as an ItemsSource so that the user can select from the enumeration:

This doesn't work at all. Is there a way to bind an enumeration as an ItemsSource?

by Jeremy


r/programminganswers • • May 17 '14

WCF client consuming java web-service receives error in production environment: CommonSOAPFaultException: An internal WS-Security error occurred

1 Upvotes

I'm developing an ASP.NET application with WCF client that consume a web service written in java with ws-security enabled. I manage to get it working in my development environment but when i run the application in the customer's network i get this error messaje from the service:

org.jboss.ws.core.CommonSOAPFaultException: An internal error occurred WS-Security. See log for details

My first reaction was Fiddler and found that the SOAP message structure remains exactly the same as the generated in my environment. According to the network administrator the proxy / fiewall has no restriction at all. With this facts I enabled tracing for the WCF client in my application but not further details appart for this error message. I have no clue What could be causing this error? I think this is that kind of error that can have myriad of possible causes. (Hopefully) Someone have address this before? I supose that the log details that refers the message is the service log and not client log, but i have no access to the server hosting the web service.

I can post if needed the envelope generated in my IDE and the generated in the customer network box if you want to look.

This is the log from the client:

131075304USER-PChttp://ift.tt/1lrsGdY; Se está iniciando una excepción./LM/W3SVC/19/ROOT-1-130447256187189595System.ServiceModel.FaultException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089org.jboss.ws.core.CommonSOAPFaultException: An internal WS-Security error occurred. See log for details en System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) en System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) en System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) en System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) en System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) en servicioSoap.createTicket(createTicketRequest request) en servicioSoapClient.servicioSoap.createTicket(createTicketRequest request) en servicioSoapClient.createTicket(createTicket createTicket1) en dhl.dna.SolicitarTA.btnRequestTA_Click(Object sender, EventArgs e) en System.Web.UI.WebControls.Button.OnClick(EventArgs e) en System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) en System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) en System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) en System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) en System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) en System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) en System.Web.UI.Page.ProcessRequest() en System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) en System.Web.UI.Page.ProcessRequest(HttpContext context) en ASP.solicitarta_aspx.ProcessRequest(HttpContext context) en System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() en System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) en System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error) en System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) en System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) en System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) en System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags) System.ServiceModel.FaultException: org.jboss.ws.core.CommonSOAPFaultException: An internal WS-Security error occurred. See log for details

This is the binding i use:

by Elio.Batista


r/programminganswers • • May 17 '14

Will casting a variable as an object cause that variable to lose data?

1 Upvotes

Say I have the following code

... PointPair newPoint = new PointPair(123, 432); newData((Object) newPoint); ... public override void newData(Object data) { PointPair newData; if (data is PointPair) newData = (PointPair)data; else newData = new PointPair(0, 0); // Do stuff with newData }

Will my PointPair object lose data/information during the cast/uncast to/from object?

Does it matter if I use object or Object? (capital O)

by user1596244


r/programminganswers • • May 17 '14

How do I add a method to Array#size?

1 Upvotes

I want to add a one? method to Array#size so that can I say:

class Array def one? self.size == 1 end end [1].size.one? #=> true [1,2].size.one? #=> false

by feed_me_code


r/programminganswers • • May 17 '14

Multiplication Problems in MASM32

1 Upvotes

Hi. I am currently using MASM32 and am having some trouble multiplying things. I read the documentation and it makes no sense on why its not working.

 mov eax, input("X coordinate: ") mov ebx, input("Y coordinate: ") imul ebx, eax mov x, ebx print x

It should multiply the contents of ebx and eax and store the result in ebx, but it doesn't. Say you put in a 3 and a 6─all it prints is the 6.

by user2747058


r/programminganswers • • May 16 '14

How do I use groupBy in Slick 2.0?

1 Upvotes

I am trying to use groupBy in Slick 2.0 for Play! Here is what I have:

 //SELECT * FROM transaction_data GROUP BY card_id def findAllCustomers () : List[Customer] = { //find all Card ID's used. DB.withSession { implicit session => val q = for { transaction  t.cardID) } yield transaction q.list } }

by James Little