Posts

python - Library needs to store object in a Web session: suggestions on API design -

python - Library needs to store object in a Web session: suggestions on API design - i'm developing openid consumer library [1] job in 2 separate web requests: when user requests authentication library discovers info url provided user. this info used during web request when library finishes authentication. i want advice on how best design library api persisting "discovery information" between 2 requests: i inquire caller provide own session object both calls , library store , read own object it: result = openid.request(session, url) # stores discovery in `session` # ... openid.authenticate(session, auth_data) # reads discovery `session` i don't aesthetically looks inversion of control: bring own buffer, we'll utilize you. also, "session" not well-defined interface , may expose limitations. example, sessions in django default want store json-serializable objects , object representing discovery info of custom class json doesn't ...

c - When a library my program depends depends on another library -

c - When a library my program depends depends on another library - when library programme depends depends on library, shall specify both libraries when compile programme either static or dynamic linking? when compile programme dynamically linking, shall create both libraries found during loading? thanks. when exe depends on dll should add together import library a.lib linker when linking exe. when dll depends on dll b should add together import library b.lib linker when linking a.dll. when run exe both dlls shall available in search path. edit building executable module (i.e. exe or dll) comprises compiling of source files , linking compiler output libraries executable. when consume dll #include header file defines interface dll while compiling sources. import libraries of dlls (a.lib, b.lib) not required here. in sec stage of build process linker creates executable module. linker input compiler output, static libraries, import libraries of runtime ms...

c - How represent in printf a variable type unsigned long -

c - How represent in printf a variable type unsigned long - this question has reply here: how printf “unsigned long” in c? 6 answers to print var of int in printf have %i or %d should add together unsigned long %lu right format specifier unsigned long c printf

python - Searching a blob for a string -

python - Searching a blob for a string - i have base64 blob have loaded database. have decoded , need search string. blob can , contain binary (non printable) bytes. my code far simply for row in cursor: b = base64.standard_b64decode(row[2]) so need find position of string 'xyx' in b a "binary blob" string in python, can utilize str.index : i= b.index('xyx') i becomes value of 0-based index of position of 'xyx' in b . note count bytes, not characters. you can utilize str.find , if don't want raise exception in case 'xyx' not in b python string search

java - Different parameters for dev and production environments using Gradle -

java - Different parameters for dev and production environments using Gradle - in android java project gradle build configured using android studio ide, want have variables alter according build environment. for instance, if there's public static final boolean use_local_backend = false; in utils.java, production should have false value , development may want have true utilize local server debugging. i'm not expert gradle, i'd appreciate detailed guide on how configure project have 2 different properties files each environment, each has same keys different values. the simplest solution, far, move use_local_backend buildconfig : android { // other stuff here buildtypes { debug { buildconfigfield "string", "server_url", '"http://test.this-is-so-fake.com"' } release { buildconfigfield "string", "server_url", '"http://prod.this-is-so-...

c# - Why does switching my logo give me a corrupt PDF file? -

c# - Why does switching my logo give me a corrupt PDF file? - i creating pdf file in asp.net c# windows console application, using itextsharp. i have 1 piece of code. if site 'lmh', pdf can open adobe reader. if not, error: there error processing page. there problem reading document (114). here code: string applicationpath = system.io.directory.getcurrentdirectory(); pdfptable table = new pdfptable(4) { totalwidth = 800.0f, lockedwidth = true }; float[] widths = new[] { 80.0f, 80.0f, 500.0f, 140.0f }; table.setwidths(widths); table.horizontalalignment = 0; table.defaultcell.border = 0; if (activeprofile.site == "lmh") { image hmsimage = image.getinstance(applicationpath + "\\" + "hms logo.png"); hmsimage.scaletofit(80.0f, 40.0f); pdfpcell hmslogo = new pdfpcell(hmsimage); hmslogo.border = 0; hmslogo.fixedheight = 60; table.addcell(hmslogo); } else { image blankimage = image.getinstance(applicationpath + ...

How to have my PHP script make images square, while maintaining their original ratio? -

How to have my PHP script make images square, while maintaining their original ratio? - i have been developing website time now, , looking create improve 1 little detail. currently, when user creates , account, can view "my page" , sorts of things, including alter profile image default 1 have provided, whatever want. unfortunately, if upload image ratio of greater or less 1:1, i.e. 300x200, script re-size fit avatar form, keeps ratio, , makes image float top of box. here image of avatar not have 1:1 ratio: as can see, image describe above. time makes perfect square when image user uploads has 1:1 ratio. here example: obviously, unreasonable expect user upload 1:1 image. looking help me tweak script, provide, on avatar uploads, if image has 1:1 ratio, pretty much mount image black "canvas", lack of improve wording, , center image on canvas both vertically , horizontally. here mean, using image edited in photoshop give black canvas: as can see, prof...