|
Symbolic Butt posted:have some kind of order but you should never rely on them and treat them as unordered For full-on -ness, it's more accurate to say that you cannot rely on the order of set items or dict keys instead of should not: Python code:
code:
|
# ? Apr 17, 2014 02:56 |
|
|
# ? May 31, 2024 11:41 |
fletcher posted:http://stackoverflow.com/questions/20916166/how-to-play-a-gif-on-click-like-9gag-com-with-wordpress <div id="gifdiv"> <img src="staticgif.jpg" /> </div> <script type="text/javascript"> $("#gifdiv").click(function () { if ($(this).find("img").attr("data-state") == "static") { $(this).find("img").attr("src", "animatedgif.gif"); } else { $(this).find("img").attr("src", "staticgif.jpg"); } }); </script> If that's the code, do I only need to put the file name in animatedgif and staticgif? I'm completely clueless at this sorry TwoDogs1Cup fucked around with this message at 11:43 on Apr 17, 2014 |
|
# ? Apr 17, 2014 11:39 |
|
ultrafilter posted:Have you had a probability course already? Yes, but it's a couple of years ago and I can't remember poo poo. Also, it wasn't specific for CS, but more general stuff. Biology, actually, now that I think about it.
|
# ? Apr 17, 2014 12:20 |
TwoDogs1Cup posted:<div id="gifdiv"> Do you have jQuery added to your website? That code requires the jQuery library -- http://www.jquery.com. If you're not sure or don't know what that is, check it out. For testing purposes you can add jQuery's capabilities to your internet-facing website by adding the following code to your page: code:
To answer your actual question: Yep, but don't forget the preloading. Otherwise there'll be a (slight to medium-length) delay as the browser downloads the larger animated gif. The <div id='gifdiv'> creates a sort of 'box' and gives it the unique ID 'gifdiv'. The stuff inside it (i.e. inside the <div>...</div>) is its content. To begin with, we load the image into it using <img>. This is the static image, which is usually just a copy of the first frame of the animation. The following part, in the <script>, is javascript - a bit of script that tells the browser to do something fancy, and also how to handle certain events and actions. It creates an 'event handler' tied to the element with ID 'gifdiv' that awaits a 'click' event. So when somebody clicks on that element (which contains just the image, so if you click on the image that counts too) it triggers the code inside that definition. And the code checks to see if the image has an attribute called 'data-state' whose value is 'static' (which to be honest I've never used before so I'm not sure at what level that attribute is being set). If true, it changes the image itself (or rather the 'src' of the image -- where the image element loads its content from from) to the animated one. Otherwise (i.e. under the 'else' part of the conditional check) it sets it back to the static image. But what you should also have is that later bit of code they mentioned: code:
e: I'm sorry that was meant to be helpful but I haven't had any coffee today so I'm a bit of a mess. Yes you're correct about changing the file names. Just make sure the images are in the same directory as the html file that calls the javascript code. And add that bit of preloading code later inside a <script>..</script> tag. Sulla Faex fucked around with this message at 13:43 on Apr 17, 2014 |
|
# ? Apr 17, 2014 13:39 |
You'll also have to do that specifically for each image, which means you'll be copy-pasting all that code each time you add a new image. Which is messy as hell. What you'd be better off doing is something like this. It's not the best way to do it but at least it'll scale a little better. You just need to add everything under <!-- JS --> once, assuming you don't already have jQuery included. code:
|
|
# ? Apr 17, 2014 13:57 |
Thank you so much for that
|
|
# ? Apr 17, 2014 14:18 |
|
Lysidas posted:For full-on -ness, it's more accurate to say that you cannot rely on the order of set items or dict keys instead of should not:
|
# ? Apr 17, 2014 21:20 |
|
I'm not sure if this is the best place to ask this (VCS and Linux threads didn't seem appropriate), but I'm a grad student in computational physics and my personal coding projects are getting to a point where I really need some sort of management software for syncing/building/running on our computational clusters (of which there are three, and all need different build/execution scripts). I've just been using rsync over ssh, makefiles, and a lot of slightly different bash scripts, but its quickly become a huge mess. Basically I'm looking for: - Something to help me manage keeping my code on our clusters updated with all the different build configurations - Some sort of project automation software to help with execution scripts/data from different projects - Project management software in general? Or maybe some good resources/books about managing a lot of small-ish (15k personal loc + lots of libraries/utilities) projects. For reference, my development machine and our clusters all run Linux and, if it matters, all of the code is Fortran (77 uhggg) and C/C++. Obviously I could just force myself to be organized and just keep using a bunch of scripts and makefiles, but I'm a big baby and would like some nice applications to hold my hand. Any decent books or whatever about this sort of thing would be nice too, since I'm sure what I have going right now is 100% not best practices.
|
# ? Apr 20, 2014 18:31 |
Someone else can probably give more concrete recommendations, but what you seem to be looking for in general is a configuration management system. You should be able to do something basic if you keep all the logic for building and installing/running the software in a single version control repository. I.e. keep the code for every configuration in a single tree, so they are versioned together and can share code directly. Ideally, also make that the same tree where you keep the actual software source. Then have some scripting logic that lets a unified build system detect what sort of system it's being set up on and automatically pick the correct configuration. (You can use some thin, non-versioned config files or even just commandline arguments or environment variables to aid the system detection.) Later on you can then look into systems to fully automate the deployment with perhaps just a single command from a remote machine.
|
|
# ? Apr 20, 2014 19:35 |
|
Thanks for the advice, its pretty hard to search for stuff when you aren't sure what to call it, after all, Googling "code project management software" doesn't exactly give anything useful. I think once I find something to configure everything, the rest wont be too bad. I just need a decent automation tool for actually running data through the built programs (which is a question for a different thread).
|
# ? Apr 20, 2014 22:34 |
|
I've been messing around with a pH meter's serial output in MATLAB in order to begin writing a simple data logging script. Everytime I press the print button on the meter, it sends the current pH reading to its buffer which I then read and graph with MATLAB. Problem is, the 8-bit binary data (which is supposedly ASCII encoded) doesn't make any sense. Here's a an output sample: code:
code:
191 = whitespace, denoted as [] 163 = . 161 = / 159 = 0 157 = 1 155 = 2 153 = 3 151 = 4 149 = 5 147 = 6 145 = 7 143 = 8 123 = B 121 = C 111 = H 101 = M 95 = P 31 = p Which, when applied to the above output, looks like: 86 79 73 116 170 250 251 251 251 251 203 [] [] [] [] [] 4 . 1 1 8 [] [] [] [] [] [] p H [] [] [] [] [] B [] [] 177 [] 2 5 . 0 [] C [] [] [] 4 / 2 0 / 1 4 [] [] [] 3 : 1 0 [] P M 2 29 235 0 Good enough for my purposes since I can just graph the pH. However, I can't figure out what type of character encoding is being used here. Obviously I'm getting sensible consistent data. Could it be a framing error on my part or a faulty RS232-to-USB cable or something?
|
# ? Apr 21, 2014 01:40 |
|
bjobjoli posted:Could it be a framing error on my part or a faulty RS232-to-USB cable or something? If you complement those numbers, and shift them right by 1 bit, then you get something slightly more sensible: code:
ShoulderDaemon fucked around with this message at 02:02 on Apr 21, 2014 |
# ? Apr 21, 2014 01:56 |
|
This may be something incredibly simple, but I can't figure out why these numbers are rounding to whole integers:code:
|
# ? Apr 21, 2014 13:25 |
|
You're declaring yNew as a long herecode:
code:
|
# ? Apr 21, 2014 13:37 |
|
Karl Sharks posted:All of my new y values are rounded to the whole digit, making my regression inaccurate. We've barely done anything in VBA in this class, so I don't know if it's doing integer division somewhere implicitly, even if I change all of the variable types to Long out of precaution. Longs are integers. You are explicitly using integers for everything in that code.
|
# ? Apr 21, 2014 14:35 |
|
ToxicFrog posted:Longs are integers. You are explicitly using integers for everything in that code. Oh, for whatever reason when I used longs to get around a memory overflow problem I thought they were just better than doubles. I tried using all doubles as well, but the answer is still off a bit, so it threw me off from that solution. Thanks.
|
# ? Apr 21, 2014 18:35 |
|
Karl Sharks posted:Oh, for whatever reason when I used longs to get around a memory overflow problem I thought they were just better than doubles. I tried using all doubles as well, but the answer is still off a bit, so it threw me off from that solution. Floating-point types will pretty much always be off a bit, it just depends on how much accuracy you need: https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems You might want to look into some kind of Decimal type and see if that works for you, but this is basically One Of Those Things
|
# ? Apr 21, 2014 20:08 |
|
Karl Sharks posted:I tried using all doubles as well, but the answer is still off a bit, so it threw me off from that solution. By any chance would y_values(i) be close to zero for some i?
|
# ? Apr 21, 2014 21:34 |
|
Okay, I need a little advice on how to model something. I'm trying to make a skill planner for a video game, and I'm not sure how I should define the skills. The deal is that each individual skill, e.g. 'swords' or 'poison', are the subset of a larger set of more general skills. These general skills are themselves a subset of a particular field, e.g. 'physical' or 'social'. Each set of general skills and each field have an associated skill learning modifier, that can be positive or negative. A general skill's overall modifier is the sum of the points in each subskill, plus a mood-based modifier. The modifier for a particular field, on the other hand, is ONLY the sum of the subskills' points. It might make more sense if I show you how I have a field defined right now: Python code:
I'm wondering if this isn't the best way to store this information. I was thinking I could set the Social field's modifier as such: Python code:
|
# ? Apr 22, 2014 17:26 |
|
Beware hierarchical data storage. They make one kind of query very easy, but every other kind of query a nightmare. Either use a pair of maps - one from subskill names to values and one from parent skills to subskills - or use an object for each skill with links to its parent/children, or better yet learn you some SQL. Also don't store the modifier for a parent skill if it's wholly defined by the sum of its subskills' modifiers. That's data replication and it's a bad idea because when you need to change something, you need to change it in two places. Instead, just store the mood and the subskill modifiers, and compute the parent skill modifiers when you need them. coffeetable fucked around with this message at 17:38 on Apr 22, 2014 |
# ? Apr 22, 2014 17:35 |
|
Learn a little basic data modelling. It will save you much grief as you continue to work with data structures. I would have a read on something like this: http://www.agiledata.org/essays/dataModeling101.html before trying to learn SQL (cart before the horse).
|
# ? Apr 22, 2014 18:19 |
I would suggest storing all the skills in a single, flat map by their simple name. Then have some other data that defines the skills' relationships (affinities), so you for each skill can look up its group and category. You may even want to make multiple look-up maps to go from either end. An approach you can take in defining the data storage could be to initially declare the skills in a way similar to the hierarchic form you use right now, but include only the skill names there. Use those data to then generate the other look-up maps. Defining some data in a simple but hard-to-work-with form but then transforming it into an easier-to-work-with form at runtime is a technique I use often myself.
|
|
# ? Apr 22, 2014 18:33 |
|
I am developing a web application which will be accessed from an html container within a native IOS app. Currently I am testing functionality in safari which hopefully will be similar to the html container. One thing I noticed is that the click action on the checkbox selectors and radio buttons is painfully slow. My menu items were also experiencing this behavior when I was waiting for the 'click' action. Instead of listning for this I switched to the 'touchstart'code:
|
# ? Apr 25, 2014 01:28 |
|
DholmbladRU posted:I am developing a web application which will be accessed from an html container within a native IOS app. Currently I am testing functionality in safari which hopefully will be similar to the html container. One thing I noticed is that the click action on the checkbox selectors and radio buttons is painfully slow. My menu items were also experiencing this behavior when I was waiting for the 'click' action. Instead of listning for this I switched to the 'touchstart' You may wish to try something like this library: https://github.com/ftlabs/fastclick
|
# ? Apr 25, 2014 01:46 |
|
I'm trying to figure out a way to create a list of files that contains numbers in their name that range from 0-63 like so:code:
example output: code:
|
# ? Apr 27, 2014 06:53 |
|
jimmsta posted:I'm trying to figure out a way to create a list of files that contains numbers in their name that range from 0-63 like so: You could use two for loops. In Ruby, this would create a file called out.txt that contained your list: code:
edit: fixed an off by one error. Kumquat fucked around with this message at 07:28 on Apr 27, 2014 |
# ? Apr 27, 2014 07:13 |
|
python would be most useful, mostly so I can learn how to do this sort of stuff in python... I'll take the ruby script though, I've been meaning to spend some time learning ruby edit: ooo, that's awesome and simple! I think I'll spend some more time on ruby. Gave it a try a long time ago, but never really progressed past chapter 1... Hell, I justified a purchase of a Mac to develop Ruby apps, and never ended up using it for that purpose. Thanks again! edit2: I wanted to add a backslash in, which lead me to looking for appropriate escape characters. Thanks to you, I now know how to do this sort of operation for the future! jimmsta fucked around with this message at 07:54 on Apr 27, 2014 |
# ? Apr 27, 2014 07:27 |
|
Python has a product function in itertools (what you're asking about is a Cartesian product):Python code:
|
# ? Apr 27, 2014 07:33 |
|
jimmsta posted:python would be most useful, mostly so I can learn how to do this sort of stuff in python... I'll take the ruby script though, I've been meaning to spend some time learning ruby This will do it in python. There is certainly a prettier way to do it, but it's been a minute since I've used python and I'm tired. code:
|
# ? Apr 27, 2014 07:33 |
|
Here's how I'd do it in gforth:code:
code:
Internet Janitor fucked around with this message at 17:51 on Apr 27, 2014 |
# ? Apr 27, 2014 15:58 |
|
jimmsta posted:python would be most useful, mostly so I can learn how to do this sort of stuff in python... I'll take the ruby script though, I've been meaning to spend some time learning ruby Honestly this is something you can do easily in every* language, once you understand loops and that language's way of handling output. You can also use fancy features like in SurgicalOntologist's example, but there's always the general workmanlike "loop inside a loop" way of working through all the combinations. Try doing it in Python, if you understand how the Ruby one is working you should be able to handle it
|
# ? Apr 27, 2014 17:51 |
|
In bash this is dead easy code:
|
# ? Apr 27, 2014 17:53 |
|
I don't understand oauth, what's stopping just about anyone from extracting the client id and then using permissions users have granted to my app in their own app?
|
# ? Apr 28, 2014 19:49 |
|
Getting an access token requires both the client ID and client secret, and the client secret is supposed to sit on a server under your control, not in the app.
|
# ? Apr 28, 2014 20:41 |
|
I was looking at https://developers.google.com/drive/web/auth/web-client and it all sounded like it'd happen in javascript served to users and not my hypothetical server at all.
|
# ? Apr 28, 2014 21:18 |
|
Doing everything on the client is unfortunately pretty common. I've had trouble getting people to care about the fact that it's completely insecure.
|
# ? Apr 28, 2014 21:25 |
|
I did click the "Web (Server-side)" link first but then went to the client-side page because the server-side one said "If your application does not require offline access to user data, consider using the client-side authorization flow, which can be implemented using only JavaScript and HTML."
|
# ? Apr 28, 2014 21:38 |
|
The thing that stops people commandeering your client id is that they can't run JS code on your domain. If you try running your application on a different domain, you'll see the client library error out when it tries to authenticate because it doesn't match what you've set in the console.
|
# ? Apr 29, 2014 10:23 |
|
That wouldn't stop someone with a spoofed client library that doesn't do that check, would it?
|
# ? Apr 29, 2014 17:57 |
|
|
# ? May 31, 2024 11:41 |
|
Can anyone tell me what causes this mess of javascript to open a new window in IE instead of the User's default browser? Sorry it's unformatted. It was all on one single line when I copied it. http://pastebin.com/jRN178qY This is some script I inherited which is evidently something called "Cool Tree JS" that a predecessor of mine put into place nearly a decade ago. I can see it calling "navigator.appVersion" but does that just mean it's going to use whatever browser the link is clicked from? The page with the links gets rendered in a separate, home-brewed, program that we use here. The links themselves are part of another document that this one references. Only the bit at the end seems to reference anything browser specific- code:
edit- I think our "home-brewed" application itself is choosing what browser to render this in, and it's likely choosing IE since it knows IE will be installed on any of the workstations it's run from. TheEffect fucked around with this message at 20:01 on Apr 29, 2014 |
# ? Apr 29, 2014 18:49 |