|
Ruby automatically promotes a Fixnum to a Bignum when the value is too large to be held in a Fixnum. This is very sweet of it, but is also a gigantic pain in the rear end when you're doing bitwise operations where you want bits to fall on the floor. Is there any way to disable this, so that you can do normal integer-based bitwise operations?
|
# ¿ Feb 27, 2008 22:30 |
|
|
# ¿ Apr 27, 2024 06:42 |
|
derdewey posted:Just a thought, how about testing the object with object.kind_of?(Bignum) or object.kind_of(Fixnum)? That way you know what bitmask to use. But ya, I think ruby's magical transformations can get in the way when you're doing something 'fancy'. Well, all that I'm trying to do is implement the Jenkins one-at-a-time hashing algorithm. It's a very simple algorithm (here's how it would work if auto-conversion was disabled): code:
If I could just xor the top-half of the Bignum with itself, that would work. But I'm not quite sure how I would go about doing that.
|
# ¿ Feb 27, 2008 22:49 |
|
Popcorn Sutton posted:Why is it breaking tables? You don't have a 'do' to go along with your 'while'. Also, while loops aren't very ruby idiomatic. You could try something like this instead: code:
|
# ¿ Apr 26, 2008 16:43 |
|
Two dirt-simple Ruby questions: 1) Let's say that I have a string that's "ENTRY9_blahblah". I need to pull out that 9 as an integer. There must be a better way to do this than either code:
code:
2) I have a bunch of numbers stored as fixed-width strings in hex. For example, I'll have "12345678abcdef01" which I want to extract as 1 number with a value of 0x12345689, 1 number with a value of 0xabcd and 1 more number with a value of 0xef01. Currently I'm doing this: code:
|
# ¿ Jul 20, 2008 03:45 |
|
Hop Pocket posted:There might be a simpler shorthand for regexes, but you would want to use a regex instead of unpack to do this. Cool, thanks. I would probably do code:
|
# ¿ Jul 20, 2008 07:02 |
|
drjrock_obgyn posted:So unpack might be the fastest, but marginally. I'd use the regex for readability. Hrm, interesting. I'd not played with benchmark before. I found out that my ugly-looking current approaches are actually the fastest by a long shot: code:
VVVVVVVVVVVVVVVVVVVVVVVVVV Plastic Jesus fucked around with this message at 19:12 on Jul 20, 2008 |
# ¿ Jul 20, 2008 15:11 |
|
Is it possible to load the code for a lambda from a file? I want to do this:quote:[twitch@varial]$ cat blah.test and be able to just invoke 'a' like I would if I did this: quote:a = lambda { puts "helu from the test" } But this is what happens: quote:>> a.call I have a fairly ugly work-around, but I really want to be able to attach a method to an object at runtime, with the code for that method stored in a flat file.
|
# ¿ Jun 8, 2009 17:00 |
|
skidooer posted:
That rules, but 1) there will be a file open/close every time it's invoked and 2) you can't pass args to Kernel.load
|
# ¿ Jun 8, 2009 17:29 |
|
skidooer posted:
w00t, thank you. I now feel dim, but thanks.
|
# ¿ Jun 8, 2009 18:06 |
|
Edit: Grrrrrrrrrr...nevermind, fixed it. Problem was NoScript. Plastic Jesus fucked around with this message at 23:12 on Jan 19, 2011 |
# ¿ Jan 19, 2011 23:03 |
|
I want to use the Linked In gem, but my app also uses Omniauth. Omniauth requires a newer version of oauth than the Linked In gem specifies, and Linked In specifies an exact version rather than '>='. This is easy to fix locally, but it'll break when I push to Heroku since Heroku will download the linkedin gem. Is there any clean way to supply a gemfile when pushing to Heroku?
|
# ¿ Jan 21, 2011 01:05 |
|
enki42 posted:I had the exact same problem, and fixed it locally and forked the linked in gem and pointed it to my own git repository. You can use mine if you like: Thanks for this. I have no clue why it didn't occur to me to use github but it didn't. Wait, right, it's because I'ma deeply stupid man.
|
# ¿ Jan 22, 2011 02:09 |
|
What's the correct RESTful way to do a site-wide search? That is, the search itself will cover multiple models and I'm not quite sure what the "right" route is. Should it just be application#search? That seems strange.
|
# ¿ Feb 16, 2011 17:07 |
|
BonzoESC posted:For a generic search, I'd probably make the controller "Searches" or "SiteSearch", talking to a "SiteSearch" model that handles interaction with ThinkingShinx or whatever engine you end up using. I created a controller and view for search, but I don't see why it needs a model. I could be wrong about this, as I'm usually wrong about these things. ThinkingSphinx is out because Heroku doesn't support it, but I'm looking at WebSolr as an alternative.
|
# ¿ Feb 16, 2011 18:45 |
|
Pardot posted:Also check out index tank. I haven't used them myself but it looks great. That looks like it's geared toward searching documents rather than databases. Which is awesome, but I need the ability to quickly search a crapload of database columns spread across several tables. I also like that I can test Solr locally for free during dev.
|
# ¿ Feb 16, 2011 20:04 |
|
Soup in a Bag posted:Read up on Hash.new in the core docs. If you give the Hash a default object or block, that object will be used or that block evaluated whenever you reference a non-existent key. This needs further explanation because it's really confusing when you start programming ruby: code:
code:
code:
code:
|
# ¿ Jun 19, 2011 05:50 |
|
smug forum rear end in a top hat posted:I'm starting to use OmniAuth. If I'm understanding correctly, it only connects with the Facebook API when a user needs to be authorized. Can I pull data from a user's facebook profile at will with OmniAuth? You send a request to Facebook to access a user's account on his behalf. Facebook asks the user if that's cool. If the user says OK you get back a token and a secret to use later to access the user's info. OmniAuth handles negotiating with Facebook and gets the user token/secret for you. It's then on you to use those credentials (in conjunction with your application's key and secret) to actually access the data. There are lots of Facebook gems out there to handle the heavy lifting for you.
|
# ¿ Jun 23, 2011 19:39 |
|
You really, really, really don't want to execute shell commands from a script that accepts user-supplied data. I also doubt that you'd want to be able up/down a network interface or change its IP address via a web application.
|
# ¿ Jun 24, 2011 04:18 |
|
BonzoESC posted:The Post model isn't the Group membership: I think he wants this code:
|
# ¿ Jul 9, 2011 00:28 |
|
I've run into something in Rails 3 that I don't understand. Assume I have the following models:code:
code:
code:
|
# ¿ Jul 12, 2011 23:04 |
|
skidooer posted:If we add brackets, your code is equivalent to this: Do'h, thanks. I assumed that it was something syntactical I was missing from staring at the same code for too long. Thanks also for the tip of adding a setter method, which may be useful for more than 1 reason.
|
# ¿ Jul 13, 2011 00:06 |
|
Stup posted:Thanks for all your help! Off to do a little reading now. BTW you probably don't need a custom validator, For instance, you can just do code:
|
# ¿ Jul 18, 2011 06:44 |
|
Obsurveyor posted:
Here is some more efficient code (calls COUNT() in SQL rather than selecting and iterating through each member). code:
|
# ¿ Jul 19, 2011 16:50 |
|
I'm using highcharts and would like to render the charts via a partial called from my view and it's not working at all. I have a partial called '_chart.js.erb' that contains the javascript to create and render the chart, but if I do:code:
code:
code:
code:
code:
|
# ¿ Jul 20, 2011 00:11 |
|
In case anyone's run into the same javascript partial rendering problem I posted about earlier, I managed to fix it. I put the javascript in a haml file and did a "render :partial => 'chart.js'" and now everything is fine. Something doesn't feel right about having to supply the ".js" but whatever it's good enough for now.
|
# ¿ Jul 20, 2011 17:40 |
|
My application serves profile images and I don't want any schlub who knows the URL for the image to be able to load it. That part is easy, I control access in Photos#show and use send_data (photos are stored in the DB btw). However it looks like browsers aren't caching the photos, which makes page load times unnecessarily long. This feels like a stupidly basic question, but what should I do here to speed up loads? Is there any way I can provide an etag before the controller method is invoked and I have to deal with the database hit?
|
# ¿ Jul 27, 2011 06:50 |
|
Pardot posted:A couple of things to try, more or less in order: Thanks for this. I'm hesitant to provide a max-age since the images do change and not on a predictable basis. I now set Etag and Last-Modified in PhotoController#show but unless the browser sends a HEAD request before each GET are those going to matter?
|
# ¿ Aug 1, 2011 22:41 |
|
A MIRACLE posted:I think SASS is pretty neat. But do I have to leave the Sass CLI listener open and watching my .scss files for diffs, or can the interpreter just use them un-converted by virtue of having the .scss extension? Windows dev here. They have to be converted to regular CSS on-disk. You don't strictly have to leave the converter running all the time, that's just a nice-to-have when you're testing/tweaking your scss mods.
|
# ¿ Aug 9, 2011 16:29 |
|
Bob Morales posted:What's going on here? It means 'loop through indexes 1 to 99 in the array @promotion.evaluations'. for the c folk this would be code:
|
# ¿ Aug 10, 2011 21:15 |
|
So...Rails 3.1 is scheduled to drop tomorrow. Anyone have a decent set of links for getting up to speed on things? So far I've not touched it and have just cobbled together info from the links in this 3 month old blog post. In particular I'd appreciate thorough write-ups of asset pipelines and engines.
|
# ¿ Aug 30, 2011 07:18 |
|
A MIRACLE posted:looked it up. heroku has pretty extensive documentation. Not idling worker dynos is really loving annoying. I realize it's only $34/month but it's dumb to wind down the free web dyno while leaving the worker dyno up, doing absolutely nothing. Edit: So this happened. Read about it here. Plastic Jesus fucked around with this message at 04:18 on Aug 31, 2011 |
# ¿ Aug 31, 2011 01:00 |
|
|
# ¿ Apr 27, 2024 06:42 |
|
Smol posted:Is there a good way to make action caching worth with multiple formats? As far as I can tell, Rails doesn't seem to care about the Accept header when determining cache keys, so when I enable action caching, Rails will always return the response to the first format that was requested (all formats will have the same cache key). With Action Caching it should just work out of the box, e.g. cache JSON separately from HTML or XML. With Page Caching I have no idea what would happen, but you probably don't want page caching...
|
# ¿ Feb 21, 2012 01:00 |