Posts

java - How can I define a variable within an object with another variable -

the title might little confusing want know how can change ' b ' part in mainsave.b define within object. here code far public void getitem(int a, string b) { mainsave.b = a; } the values being sent piece of code in class called story. want them stored in object of class savefile 'mainsave' is if (command_string.equals("1")) { try {thread.sleep(1500);} catch (interruptedexception e) {} system.out.println("you search shed thouroughly , find axe not else..."); int item = 1; string axe = "axe"; getitem(item,axe); try {thread.sleep(1500);} catch (interruptedexception e) {} area1(); } the error when trying compile first part "cannot find symbol - variable b" simply cannot since java statically typed language. variables names must realize @ compile time. i don't suggest possible reflection coding.

c++ - compile error for boost::date_time::days_until_weekday -

i'm toying around boost::date_time . while doing so, came upon days_until_weekday ( documentation link ) function appears highly useful me. unfortunately, compile time error following snippet date f(date d){ return next_weekday(d, boost::date_time::weekdays::friday); } reading > in file included > /usr/include/boost/date_time/gregorian/gregorian_types.hpp:25:0, > /usr/include/boost/date_time/posix_time/posix_time_config.hpp:18, > /usr/include/boost/date_time/posix_time/posix_time_system.hpp:13, > /usr/include/boost/date_time/posix_time/ptime.hpp:12, > /usr/include/boost/date_time/posix_time/posix_time.hpp:15, > prog.cpp:3: /usr/include/boost/date_time/date_generators.hpp: in instantiation of > 'typename date_type::duration_type > boost::date_time::days_until_weekday(const date_type&, const > weekday_type&) [with date_type = boost::gregorian:...

Salesforce Apex: test that callout hasn't been made -

i want write unit test checks callout hasn't been made trigger. know how test if callout made correctly - implementing httpcalloutmock: global class myhttpcalloutmock implements httpcalloutmock { global httpresponse respond(httprequest req) { //test httprequest here } } but if no http request made, respond() method won't called. approach doesn't test if request made @ all. need this: httprequest.assertnorequestshavebeenmade(); how do that? so figured out. turns out salesforce has methods test.starttest() , test.stoptest() make asynchronous callouts synchronous: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_start_stop_test.htm after making callouts synchronous it's easier test them.

Python Check txt variable loop -

i need function check in name.txt variable if variable changed print 1 , again if variable 2 times change again print 1. possible in python? http://pastebin.com/qa0ed3nm fr = open("plik.txt",'r') first_length = len(str(fr.read())) while true: text = str(fr.read()) if(len(text)!=first_length): fr.close() fw = open("plik.txt","w") fw.write(text) fw.close() print("done") break; may function can help: def checkchange(filename, oldcontent): fsrc = open(filename, 'r') actualcontent = fsrc.read() fsrc.close() if actualcontent != oldcontent: print(1) return actualcontent

C# Looping through Dictionary and summing values for Keys -

i have dictionary<string, decimal?> , , able sum decimals distinct string. have below inputs in dictionary, "1", 20.00 "1", 35.00 "2", 10.00 "3", 15.00 "3", 30.00 i following output new dictionary "1", 55.00 "2", 10.00 "3", 45.00 i'm guessing foreach(var item in dictionary) { newdictionary.add(not sure go here, maybe sort of linq query distinct , sum?); } the keys in dictionary can't repeated, 2 first entries won't fit in dictionary. i think may have list of objects can loop, can use dictionary store total each "key" something like dictionary<string, double> totals = new dictionary<string, double>(); list<tuple<string, double>> entries = new list<tuple<string, double>>() { new tuple<string, double>("1",20.00), new tuple<string, double>("1",35.00), ...

node.js - How do I replace a string in a PDF file using NodeJS? -

i have template pdf file, , want replace marker strings generate new pdf files , save them. what's best/simplest way this? don't need add graphics or fancy, simple text replacement, don't want complicated. thanks! edit: found hummusjs , i'll see if can make progress , post here. i found question searching, think deserves answer. found answer brightide here: https://github.com/galkahana/hummusjs/issues/71#issuecomment-275956347 basically, there powerful hummus package uses library written in c++ (crossplatform of course). think answer given in github comment can functionalized this: var hummus = require('hummus'); function replacetext(sourcefile, targetfile, pagenumber, findtext, replacetext) { var writer = hummus.createwritertomodify(sourcefile, { modifiedfilepath: targetfile }); var modifier = new hummus.pdfpagemodifier(writer, pagenumber); var sourceparser = writer.createpdfcopyingcontextformodi...

Calling dll in python 3 with LPSTR -

i have .dll named my.dll , 4 functions, called in python 3.5 using: mydll = ctypes.cdll.loadlibrary(path:\to\my.dll) my problem calling function has lpstr : #include "stdafx.h" #include "newheader.h" double _stdcall pain_function(double arg1, double arg2, lpstr arg_string_with_spaces) the other 3 calls my.dll work fine. below code tried pain_function : import ctypes ctypes import wintypes # load dll mydll = ctypes.windll(path:\to\my.dll) # call function pain_function = mydll.pain_function # typecast arguments pain_function.argtypes = [ctypes.c_double, ctypes.c_double, wintypes.lpstr] # typecast return pain_function.restype = ctypes.c_double pain_return = pain_function(arg1, arg2, some_string) pain_return returns nonsensical number. tried variations, along lines of: some_string = ctypes.create_string_buffer(b' ' * 200) i have looked here among other places: python-ctypes-prototype-with-lpcstr-out-parameter using ...