Search Results

Search found 1421 results on 57 pages for 'arbitrary'.

Page 9/57 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • PHP given a series of arbitrary numbers, how can I choose a logical max value on a line graph?

    - by stormist
    I am constructing a line graph in PHP. I was setting the max value of the line graph to the max value of my collection of items, but this ended up making the graph less readable you are unable to view the highest line on the graph as it intersects with the top of it. So what I need is basically a formula to take a set of numbers and calculate what the logical max value of on the line graph should be.. so some examples 3500 250 10049 45394 434 312 Max value on line graph should probably be 50000 493 412 194 783 457 344 max value on line graph would ideally be 1000 545 649 6854 5485 11545 In this case, 12000 makes sense as max value So something as simple as rounding upward to the nearest thousandth might work but I'd need it to progressively increase as the numbers got bigger. (50000 instead of 46,000 in first example) The maximum these numbers will ever be is about a million. Any recommendations would be greatly appreciated, thank you.

    Read the article

  • How to prevent arbitrary code execution vulnerability in our programs?

    - by Calmarius
    You always read in changelogs when your system or browser or any program updates that they fixed a bug that made possible that an attacker can execute any code in your computer with a forged website, or attacking your computer with carefully forged packets, etc... Because you read it so often that means any program can have similar vulnerabilites... What causes this? how to design our programs to prevent similar issues?

    Read the article

  • What is the most efficient way to encode an arbitrary GUID into readable ASCII (33-127)?

    - by mark
    Dear ladies and sirs. The standard string representation of GUID takes about 36 characters. Which is very nice, but also really wasteful. I am wondering, how to encode it in the shortest possible way using all the ASCII characters in the range 33-127. The naive implementation produces 22 characters, simply because 128 bits / 6 bits yields 22. Huffman encoding is my second best, the only question is how to choose the codes.... Any more ideas? Thanks. P.S. The encoding must be lossless, of course.

    Read the article

  • How to find nearest week day for an arbitrary date?

    - by Stig Brautaset
    Is there a more elegant way than the below to find the nearest day of the week for a given date using JodaTime? I initially thought setCopy() would be it, but this sets the day to the particular day in the same week. Thus, if ld is 2011-11-27 and day is "Monday" the following function returns 2011-11-21, and not 2011-11-28 as I want. // Note that "day" can be _any_ day of the week, not just weekdays. LocalDate getNearestDayOfWeek(LocalDate ld, String day) { return ld.dayOfWeek().setCopy(day); } Below is a work-around I came up with that works for the particular constraints in my current situation, but I'd love to get help find a completely generic solution that works always. LocalDate getNearestDayOfWeek(LocalDate ld, String day) { LocalDate target = ld.dayOfWeek().setCopy(day); if (ld.getDayOfWeek() > DateTimeConstants.SATURDAY) { target = target.plusWeeks(1); } return target; } Looking more into this I came up with this, which seems to be a more correct solution, though it seems awfully complicated: LocalDate getNearestDayOfWeek(LocalDate ld, String day) { LocalDate target = ld.dayOfWeek().setCopy(day); if (target.isBefore(ld)) { LocalDate nextTarget = target.plusWeeks(1); Duration sincePrevious = new Duration(target.toDateMidnight(), ld.toDateMidnight()); Duration untilNext = new Duration(ld.toDateMidnight(), nextTarget.toDateMidnight()); if (sincePrevious.isLongerThan(untilNext)) { target = nextTarget; } } return target; }

    Read the article

  • How to safely let users run arbitrary Ruby code?

    - by igul222
    I realize this sounds a little crazy, but I'm working on a project for which I need a server to run user-provided Ruby code and return the result. I'm looking to prevent something like this: system("rm -rf /") eval("something_evil") # etc... I'm sure there must be some reasonably safe way to do this, as it already exists at places like tryruby.org. Any help is greatly appreciated, thanks!

    Read the article

  • how to diff / align Python lists using arbitrary matching function?

    - by James Tauber
    I'd like to align two lists in a similar way to what difflib.Differ would do except I want to be able to define a match function for comparing items, not just use string equality, and preferably a match function that can return a number between 0.0 and 1.0, not just a boolean. So, for example, say I had the two lists: L1 = [('A', 1), ('B', 3), ('C', 7)] L2 = ['A', 'b', 'C'] and I want to be able to write a match function like this: def match(item1, item2): if item1[0] == item2: return 1.0 elif item1[0].lower() == item2.lower(): return 0.5 else: return 0 and then do: d = Differ(match_func=match) d.compare(L1, L2) and have it diff using the match function. Like difflib, I'd rather the algorithm gave more intuitive Ratcliff-Obershelp type results rather than a purely minimal Levenshtein distance.

    Read the article

  • Can Fluent NHibernate be configured to use an arbitrary prefix on a property backing field?

    - by dommer
    I'm currently using a convention to (auto)map collection properties to backing fields in Fluent NHibernate. So, I map a property "Orders" to a field "_orders". The convention I'm using to do this is: public class HasManyAccessConvention : IHasManyConvention { public void Apply(IOneToManyCollectionInstance instance) { instance.Access.CamelCaseField(CamelCasePrefix.Underscore); } } Can I write a convention that maps a (collection) property to a field with a non-standard prefix (ignoring whether this is good coding practice for the present)? So, the property "Orders" would be mapped to "xyz_orders", for example. If so, how would I go about this?

    Read the article

  • How to convert an arbitrary object to String with EL? (calling toString())

    - by hstoerr
    Is there any way to call toString() on an object with the EL? (I need the String representation of an enum as index in a map in a JSP EL expression.) I hoped something like ${''+object} would work like in java, but EL isn't that nice, and there does not seem to be any function that does it. Clarification: I have a variable somemap that maps Strings to Strings, and I have a variable someenum that is an enumeration. I'd like to do something like ${somemap[someenum.toString()]}. (Of course .toString() does not work, but what does?)

    Read the article

  • How can I handle arbitrary text as "nouns" in Inform 7?

    - by Beska
    In Inform, I'd like to be able to create a new action, and have it be able to work on aribitrary text. I can easily create a new action that will work on existing things. Finding is an action with past participle found, applying to one thing. Understand "Find [something]" as finding. Carry out finding: say "You find [the noun]." But this only works on items that exist within the game world. If I try to "find fdsljk", for instance, it will fail because I haven't created a "fdsljk". I'd like to be able to "find fdsljk" and then be able to grab that extra text and respond with it...something like "You find the fdsljk." I was thinking that something like A foo is a kind of value. Finding is an action with past participle found, applying to one foo. Understand "Find [something]" as finding. Carry out finding: say "You find [the foo]." might be close...but it doesn't work. I get an error that reads: You wrote 'say "You find [the foo]."' , and in particular 'the foo': but this asked to say something of a kind which can't be said, or rather, printed. Although this problem can arise when you use complicated text substitutions which come in variant forms depending on the kinds of value used, far more often what this means is just that you tried to use a substituted value (e.g., in 'say "The dial reads [V]."') of a kind which could not be printed out. For instance, if V is a number or a piece of text, there is no problem: but if V is a parsing topic, say an entry in a 'topic' column of a table, then this problem will arise. The italics are mine, and highlight the key...I think this should be doable, but I'm taking the wrong path. Clues?

    Read the article

  • Creating serializeable unique compile-time identifiers for arbitrary UDT's.

    - by Endiannes
    I would like a generic way to create unique compile-time identifiers for any C++ user defined types. for example: unique_id<my_type>::value == 0 // true unique_id<other_type>::value == 1 // true I've managed to implement something like this using preprocessor meta programming, the problem is, serialization is not consistent. For instance if the class template unique_id is instantiated with other_type first, then any serialization in previous revisions of my program will be invalidated. I've searched for solutions to this problem, and found several ways to implement this with non-consistent serialization if the unique values are compile-time constants. If RTTI or similar methods, like boost::sp_typeinfo are used, then the unique values are obviously not compile-time constants and extra overhead is present. An ad-hoc solution to this problem would be, instantiating all of the unique_id's in a separate header in the correct order, but this causes additional maintenance and boilerplate code, which is not different than using an enum unique_id{my_type, other_type};. A good solution to this problem would be using user-defined literals, unfortunately, as far as I know, no compiler supports them at this moment. The syntax would be 'my_type'_id; 'other_type'_id; with udl's. I'm hoping somebody knows a trick that allows implementing serialize-able unique identifiers in C++ with the current standard (C++03/C++0x), I would be happy if it works with the latest stable MSVC and GNU-G++ compilers, although I expect if there is a solution, it's not portable.

    Read the article

  • Convert arbitrary length to a value between -1.0 a 1.0?

    - by TheDarkIn1978
    How can I convert a length into a value in the range -1.0 to 1.0? Example: my stage is 440px in length and accepts mouse events. I would like to click in the middle of the stage, and rather than an output of X = 220, I'd like it to be X = 0. Similarly, I'd like the real X = 0 to become X = -1.0 and the real X = 440 to become X = 1.0. I don't have access to the stage, so i can't simply center-register it, which would make this process a lot easier. Also, it's not possible to dynamically change the actual size of my stage, so I'm looking for a formula that will translate the mouse's real X coordinate of the stage to evenly fit within a range from -1 to 1.

    Read the article

  • Haskell: How to compose `not` with a function of arbitrary arity?

    - by Hynek -Pichi- Vychodil
    When I have some function of type like f :: (Ord a) => a -> a -> Bool f a b = a > b I should like make function which wrap this function with not. e.g. make function like this g :: (Ord a) => a -> a -> Bool g a b = not $ f a b I can make combinator like n f = (\a -> \b -> not $ f a b) But I don't know how. *Main> let n f = (\a -> \b -> not $ f a b) n :: (t -> t1 -> Bool) -> t -> t1 -> Bool Main> :t n f n f :: (Ord t) => t -> t -> Bool *Main> let g = n f g :: () -> () -> Bool What am I doing wrong? And bonus question how I can do this for function with more and lest parameters e.g. t -> Bool t -> t1 -> Bool t -> t1 -> t2 -> Bool t -> t1 -> t2 -> t3 -> Bool

    Read the article

  • Math - Convert Arbitrary Length to Range From -1.0 to 1.0?

    - by TheDarkIn1978
    how can i convert a length into a range of -1.0 to 1.0? example: my stage is 440px in length and accepts mouse events. i would like to click in the middle of the stage, and rather than an output of X = 220, i'd like it to be X = 0. similarly, i'd like the real X = 0 to become X = -1.0 and the real X = 440 to become X = 1.0. i don't have access to the stage, so i can't simply center-register it, which would make this process a lot easier. also, it's not possible to dynamically change the actual size of my stage, so i'm looking for a formula that will translate the mouse's real X coordinate of the stage to evenly fit within a range from -1 to 1.

    Read the article

  • How to gather arbitrary length list data in ASP.NET MVC.

    - by C. Ross
    I need to gather a list of items associated with another item from my user in a ASP.NET MVC project. I would like to have a controller action like bellow. [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(int x, int y, IEnumerable<int> zKeys) { //Do stuff here } How can I setup my form to pass data in this way? If data of this particular form can't be provided, what's the next best way to pass this type of information in ASP.NET MVC?

    Read the article

  • How to read arbitrary number of values using std::copy?

    - by Miro Kropacek
    Hi, I'm trying to code opposite action to this: std::ostream outs; // properly initialized of course std::set<int> my_set; // ditto outs << my_set.size(); std::copy( my_set.begin(), my_set.end(), std::ostream_iterator<int>( outs ) ); it should be something like this: std::istream ins; std::set<int>::size_type size; ins >> size; std::copy( std::istream_iterator<int>( ins ), std::istream_iterator<int>( ins ) ???, std::inserter( my_set, my_set.end() ) ); But I'm stuck with the 'end' iterator -- input interators can't use std::advance and neither I can use two streams with the same source... Is there any elegant way how to solve this? Of course I can use for loop, but maybe there's something nicer :)

    Read the article

  • In Cocoa (or maybe GUI development in general) how do you specify an arbitrary number of things tile

    - by RankWeis
    I'm new to creating GUI's, everything I've done up until this point is using the command line. I'm trying to create a port of minesweeper to the macintosh, as an experiment, and I've got the CLI working, but I'm running into walls everywhere with the gui. The first thing it seems I have to do, however, is be able to tile n x m 'boxes' for grid - and I'm not sure how to do that. The information is ready to be handed to it, but I don't know where to do it, or how. Also, if anyone has any recommendations for sites/Cocoa development books, feel free to drop them in here... Thanks!

    Read the article

  • Data structure for pattern matching.

    - by alvonellos
    Let's say you have an input file with many entries like these: date, ticker, open, high, low, close, <and some other values> And you want to execute a pattern matching routine on the entries(rows) in that file, using a candlestick pattern, for example. (See, Doji) And that pattern can appear on any uniform time interval (let t = 1s, 5s, 10s, 1d, 7d, 2w, 2y, and so on...). Say a pattern matching routine can take an arbitrary number of rows to perform an analysis and contain an arbitrary number of subpatterns. In other words, some patterns may require 4 entries to operate on. Say also that the routine (may) later have to find and classify extrema (local and global maxima and minima as well as inflection points) for the ticker over a closed interval, for example, you could say that a cubic function (x^3) has the extrema on the interval [-1, 1]. (See link) What would be the most natural choice in terms of a data structure? What about an interface that conforms a Ticker object containing one row of data to a collection of Ticker so that an arbitrary pattern can be applied to the data. What's the first thing that comes to mind? I chose a doubly-linked circular linked list that has the following methods: push_front() push_back() pop_front() pop_back() [] //overloaded, can be used with negative parameters But that data structure seems very clumsy, since so much pushing and popping is going on, I have to make a deep copy of the data structure before running an analysis on it. So, I don't know if I made my question very clear -- but the main points are: What kind of data structures should be considered when analyzing sequential data points to conform to a pattern that does NOT require random access? What kind of data structures should be considered when classifying extrema of a set of data points?

    Read the article

  • Billboarding restricted to an axis (cylindrical)

    - by user8709
    I have succesfully created a GLSL shader for a billboarding effect. I want to tweak this to restrict the billboarding to an arbitrary axis, i.e. a billboarded quad only rotates itself about the y-axis. I use the y-axis as an example, but essentially I would like this to be an arbitrary axis. Can anyone show me how to modify my existing shader below, or if I need to start from scratch, point me towards some resources that could be helpful? precision mediump float; uniform mat4 u_modelViewProjectionMat; uniform mat4 u_modelMat; uniform mat4 u_viewTransposeMat; uniform vec3 u_axis; // <------------ !!! the arbitrary axis to restrict rotation around attribute vec3 a_position0; attribute vec2 a_texCoord0; varying vec2 v_texCoord0; void main() { vec3 pos = (a_position0.x * u_viewTransposeMat[0] + a_position0.y * u_viewTransposeMat[1]).xyz; vec4 position = vec4(pos, 1.0); v_texCoord0 = a_texCoord0; gl_Position = u_modelViewProjectionMat * position; }

    Read the article

  • jQuery: How do I insert an html string an arbitrary number of times (i.e. not with an each() function)?

    - by Sam Bivins
    I just need to take a certain html query object and append it to an html element a lot of times. I have this: var box = $("<div class='box'>&nbsp</div>"); $("#firstbox").after(box); and it works fine, but it just adds one 'box' after the #firstbox element. I'd like to do something like this: var box = $("<div class='box'>&nbsp</div>"); $("#firstbox").after(box * 6000); so that it will insert 6000 copies of that 'box' html, but this is not working. This is I'm sure the easiest thing to do, but I can't seem to find how to multiply actions like this without using the each() function, which doesn't apply here because I don't have 6000 of anything on my page. Thanks.

    Read the article

  • Code-Golf: one line PHP syntax

    - by Kendall Hopkins
    Explanation PHP has some holes in its' syntax and occasionally in development a programmer will step in them. This can lead to much frustration as these syntax holes seem to exist for no reason. For example, one can't easily create an array and access an arbitrary element of that array on the same line (func1()[100] is not valid PHP syntax). The workaround for this issue is to use a temporary variable and break the statement into two lines, but sometimes that can lead to very verbose, clunky code. Challenge I know of a few of these holes (I'm sure there are more). It is quite hard to even come up with a solution, let alone in a code-golf style. Winner is the person with in the least characters total for all four Syntax Holes. Rules Statement must be one line in this form: $output = ...;, where ... doesn't contain any ;'s. Only use standard library functions (no custom functions allowed) Statement works identically to the assumed functional of the non-working syntax (even in cases that it fails). Statement must run without syntax error of any kind with E_STRICT | E_ALL. Syntax Holes $output = func_return_array()[$key]; - accessing an arbitrary offset (string or integer) of the returned array of a function $output = new {$class_base.$class_suffix}(); - arbitrary string concatenation being used to create a new class $output = {$func_base.$func_suffix}(); - arbitrary string concatenation being called as function $output = func_return_closure()(); - call a closure being returned from another function

    Read the article

  • Efficient Multiplication of Varying-Length #s [Conceptual]

    - by Milan Patel
    Write the pseudocode of an algorithm that takes in two arbitrary length numbers (provided as strings), and computes the product of these numbers. Use an efficient procedure for multiplication of large numbers of arbitrary length. Analyze the efficiency of your algorithm. I decided to take the (semi) easy way out and use the Russian Peasant Algorithm. It works like this: a * b = a/2 * 2b if a is even a * b = (a-1)/2 * 2b + a if a is odd My pseudocode is: rpa(x, y){ if x is 1 return y if x is even return rpa(x/2, 2y) if x is odd return rpa((x-1)/2, 2y) + y } I have 3 questions: Is this efficient for arbitrary length numbers? I implemented it in C and tried varying length numbers. The run-time in was near-instant in all cases so it's hard to tell empirically... Can I apply the Master's Theorem to understand the complexity...? a = # subproblems in recursion = 1 (max 1 recursive call across all states) n / b = size of each subproblem = n / 1 - b = 1 (problem doesn't change size...?) f(n^d) = work done outside recursive calls = 1 - d = 0 (the addition when a is odd) a = 1, b^d = 1, a = b^d - complexity is in n^d*log(n) = log(n) this makes sense logically since we are halving the problem at each step, right? What might my professor mean by providing arbitrary length numbers "as strings". Why do that? Many thanks in advance

    Read the article

  • VPN iptables Forwarding: Net-to-net

    - by Mike Holler
    I've tried to look elsewhere on this site but I couldn't find anything matching this problem. Right now I have an ipsec tunnel open between our local network and a remote network. Currently, the local box running Openswan ipsec with the tunnel open can ping the remote ipsec box and any of the other computers in the remote network. When logged into on of the remote computers, I can ping any box in our local network. That's what works, this is what doesn't: I can't ping any of the remote computers via a local machine that is not the ipsec box. Here's a diagram of our network: [local ipsec box] ----------\ \ [arbitrary local computer] --[local gateway/router] -- [internet] -- [remote ipsec box] -- [arbitrary remote computer] The local ipsec box and the arbitrary local computer have no direct contact, instead they communicate through the gateway/router. The router has been set up to forward requests from local computers for the remote subnet to the ipsec box. This works. The problem is the ipsec box doesn't forward anything. Whenever an arbitrary local computer pings something on the remote subnet, this is the response: [user@localhost ~]# ping 172.16.53.12 PING 172.16.53.12 (172.16.53.12) 56(84) bytes of data. From 10.31.14.16 icmp_seq=1 Destination Host Prohibited From 10.31.14.16 icmp_seq=2 Destination Host Prohibited From 10.31.14.16 icmp_seq=3 Destination Host Prohibited Here's the traceroute: [root@localhost ~]# traceroute 172.16.53.12 traceroute to 172.16.53.12 (172.16.53.12), 30 hops max, 60 byte packets 1 router.address.net (10.31.14.1) 0.374 ms 0.566 ms 0.651 ms 2 10.31.14.16 (10.31.14.16) 2.068 ms 2.081 ms 2.100 ms 3 10.31.14.16 (10.31.14.16) 2.132 ms !X 2.272 ms !X 2.312 ms !X That's the IP for our ipsec box it's reaching, but it's not being forwarded. On the IPSec box I have enabled IP Forwarding in /etc/sysctl.conf net.ipv4.ip_forward = 1 And I have tried to set up IPTables to forward: *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [759:71213] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 500 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 4500 -j ACCEPT -A INPUT -m policy --dir in --pol ipsec -j ACCEPT -A INPUT -p esp -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -s 10.31.14.0/24 -d 172.16.53.0/24 -j ACCEPT -A FORWARD -m policy --dir in --pol ipsec -j ACCEPT -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT Am I missing a rule in IPTables? Is there something I forgot? NOTE: All the machines are running CentOS 6.x Edit: Note 2: eth1 is the only network interface on the local ipsec box.

    Read the article

  • Where's my Open-With gVim context menu option in Windows 7?

    - by David Mackintosh
    I have gVim installed. Under Vista and XP, this offered me an addition to either the object context menu of "Edit with gVim", or an addtion to the "Open With" context menu of "gVim". This would let me send arbitrary files to gVim for editing. Under Windows 7 64-bit, I have installed gVim -- twice, as it happens -- and there's no menu item. How do I add an option to send arbitrary files to gVim for viewing/editing?

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >