Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
bomblol
Jul 17, 2009

my first crapatar
So I'm working on a project that uses twitter's API in Ruby. As of right now, none of my calls check for rate limiting - it was originally a weekend experiment, so I never really bothered checking. Now however I want to wrap all my calls to my twitter client object in blocks so that it can handle the too many requests exception.
code:
puts "Checking for new replies since tweet #{@last_seen_tweet}."
  begin
    mentions = @twitter_client.mentions({since_id: @last_seen_tweet, count: 20})
  rescue Twitter::Error::TooManyRequests => error
    sleep error.rate_limit.reset_in + 1
    retry
  end
It really uglies up the code having to do this for every call. Is there some way I can make a method, such as twitter_request(request) that I could somehow pass mentions({since_id: @last_seen_tweet, count: 20}) (or whatever the equivalent would be), and then inside that method wrap the call in exceptions? I was considering creating a new class MyTwitterClient or whatever that implements method_missing, send() it to the @twitter_client after wrapping it in the exception handler. But i would like to avoid creating another class just for that. Or maybe there's a better way to do it by subclassing the twitter client class.

bomblol fucked around with this message at 00:38 on Mar 29, 2016

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...

No Safe Word posted:

You suffer from the same affliction I try to rid myself of: gratuitous use of cat (sed can take a filename as an arg)

Other commands I used to do that poo poo with regularly: less, grep, and their z* variants

I would't call it "suffering" :xd:

Really though, when I'm building one up I always start with cat. No small part of it is afraid I'll forget which sed flags actually muck my file up and I know cat is far less likely to do that. But if I just want to see how the first 10 lines are going, piping into head makes a lot more sense than hopping back to the first thing and changing that command no matter how much interstitial inefficiency is created. Do you have a limited number of times to call cat every day?

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
I feel the same way, but instead of
code:
cat f | c
I always just do
code:
<f c
because I'm lazy and typing is literally the hardest thing in the universe to do

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

bomblol posted:

It really uglies up the code having to do this for every call. Is there some way I can make a method, such as twitter_request(request) that I could somehow pass mentions({since_id: @last_seen_tweet, count: 20}) (or whatever the equivalent would be), and then inside that method wrap the call in exceptions? I was considering creating a new class MyTwitterClient or whatever that implements method_missing, send() it to the @twitter_client after wrapping it in the exception handler. But i would like to avoid creating another class just for that. Or maybe there's a better way to do it by subclassing the twitter client class.

If this were Python I'd tell you to write a decorator function, which would look something like this:
code:
def limit_rate(func):
    def limited_func(*args, **kwargs):
        try:
            func(*args, **kwargs)
        except Exception, e:
            ....try calling func again in a bit...
    return limited_func
Basically we have here a function that takes a function as an argument, creates a new function that tries to call the original function (with appropriate catch exception -> retry logic not shown here), and returns that new function. So you can call limit_rate(do_a_thing)(args to do_a_thing) and get the retry logic automatically. Python has a syntactic sugar where you can just put "@limit_rate" above the definition of a function and all references to that function will be transparently redirected through the decorator. Ruby may have something similar.

The "*args, **kwargs" bit is what a "varargs" (variable argument list) function looks like in Python. Again, Ruby presumably has something similar. Basically it allows you to pass arguments between functions without actually caring what they are, and to work with functions that can accept an arbitrary number of arguments (print/printf are common examples of this). *args is a list (tuple in Python) of arguments, and **kwargs is a dictionary of arguments that were supplied by keyword.

Harriet Carker
Jun 2, 2009

Anyone know of a good regular expressions tutorial? I'm working with Ruby and Python if it matters. Never used regular expressions before, so think something that starts from scratch.

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

dantheman650 posted:

Anyone know of a good regular expressions tutorial? I'm working with Ruby and Python if it matters. Never used regular expressions before, so think something that starts from scratch.

This helped me for Python

also try here for some regex practice

Jewel
May 2, 2009

Anyone who's familiar with stackoverflow should like this stupid twitter markov chain bot :allears:

https://twitter.com/horse_overflow

loquacius
Oct 21, 2008

So I'm having some issues with Git-SVN.

I'm trying to use it to get checkout of a very large SVN repository on a Windows computer via CygWIN -- attempts at getting a checkout via native SVN and/or Git clients have failed for various reasons, and all of my company's support scripts were written for Unix/Linux, so CygWIN appears to be my best shot. What I've been doing in the meantime is using regular SVN to get a checkout on my dev server and rsyncing all the code over to my Windows laptop for development purposes (deploying it back to the dev server for testing purposes via IntelliJ's built-in SFTP functionality), but this isn't a perfect solution, especially when large changes to how our files are organized come around (this happened last week, hence the Git-SVN experiments).

Anyway, I'm attempting to check out the repository via the following command:

code:
git svn clone -r HEAD [url]https://[/url]<svn repository URL>/trunk MAINLINE/
This triggers a big download of all the files in the repository, as expected, but inevitably somewhere along the way the sync dies with the following output:

code:
error: git-svn died of signal 11
possibly with an additional output of something like
code:
fatal: malformed index info 100644 8409fef7711cc4c7b4
So naturally I asked Google what to do in this situation, and Stack Overflow overwhelmingly seems to suggest that if I use
code:
git svn fetch
the sync will just pick up where it left off. And it does. But, the first time in every sync process that I run fetch (I have to do it several times), I get the following output:

code:
W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: '/svn/<company name>/!svn/bc/100/<repository name>/trunk' path not found
W: Do not be alarmed at the above message git-svn is just searching aggressively for old history.
This may take a while on large repositories
Checked through r<revision number>
The <revision number> part at the end will cycle up to a certain value -- around 123,400 -- and then the sync will resume, and then when it's done it attempts to individually apply every single code change from revision 123,400 up until the most recent one (at the moment, this is revision number 896,498).

Obviously, this means that the sync will take days and use up my entire hard drive. I would not like this to happen. That's why I specified "-r HEAD" in my initial clone command (I've also tried -r 896498:HEAD with no difference); the problem seems to be that fetch is just kind of ignoring that parameter.

My question: how do I either (a) keep my initial correctly-formatted clone command from dying of signal 11, or (b) when resuming it, tell fetch not to get me 750,000 loving revisions I don't want?

fake-edit: Stack Overflow has also suggested I add "--parent" to my fetch command, this results in an immediate death with the output
code:
fatal: bad revision 'HEAD'
rev-list --first-parent --pretty=medium HEAD --: command returned error: 128

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Does anyone have a favorite 'babby's first raytracer' guide or book?

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



taqueso posted:

Does anyone have a favorite 'babby's first raytracer' guide or book?

Physically Based Rendering is the most comprehensive one out there, even won a technical Oscar. Covers a lot of stuff and goes much deeper than your first raytracer but it also covers the basics in good explanations so you can probably use it as a reference while trying to make your own.

When I first made a raytracer years ago I just googled raytracer tutorials, which gives a real mixed bag but should be helpful to get bits and pieces of what's applicable to help you out.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

piratepilates posted:

Physically Based Rendering is the most comprehensive one out there, even won a technical Oscar. Covers a lot of stuff and goes much deeper than your first raytracer but it also covers the basics in good explanations so you can probably use it as a reference while trying to make your own.
Thanks. I can probably have work buy that for me, even though it isn't directly applicable to anything we do.

quote:

When I first made a raytracer years ago I just googled raytracer tutorials, which gives a real mixed bag but should be helpful to get bits and pieces of what's applicable to help you out.
Yeah, it is a real mixed bag and I didn't want to have to read 100 tutorials to find a good one or piece it all together.

raminasi
Jan 25, 2005

a last drink with no ice

The Version Control Megathread might be able to help you out.

Xerophyte
Mar 17, 2008

This space intentionally left blank

taqueso posted:

Thanks. I can probably have work buy that for me, even though it isn't directly applicable to anything we do.

PBRT is a great book. It is in fact so great that there will be an updated and expanded 3rd edition published in June-ish, which you might want to get instead.

Depending on what you want to achieve you can consider starting out with just shadertoy. You can follow a raymarching tutorial and working with just a shader strips away a lot of the annoying plumbing you'd otherwise need to do in order to get pixels on screen. Of course, there are limits to what you can do in shadertoy (exception: Inigo Quilez) but it's a good way to get started with a lot of the concepts involved in a more complicated renderer.

Star War Sex Parrot
Oct 2, 2003

taqueso posted:

Does anyone have a favorite 'babby's first raytracer' guide or book?
I rather liked this book that I found a couple of months ago: Ray Tracing in One Weekend

loquacius
Oct 21, 2008

GrumpyDoctor posted:

The Version Control Megathread might be able to help you out.

:doh: didn't realize there was one, thanks

for the record I ended up just using the native Windows installation to pull because it's way less buggy; turns out I can in fact do that and still use Unix scripts in CygWIN afterward

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

Xerophyte posted:

PBRT is a great book. It is in fact so great that there will be an updated and expanded 3rd edition published in June-ish, which you might want to get instead.

I decided to get a used copy of 2nd edition, since I saw the 3rd edition was coming soon. I don't want to wait for July 15.

I want to work on this to get a better handle on rust-lang, but the shader stuff does sound interesting.


Star War Sex Parrot posted:

I rather liked this book that I found a couple of months ago: Ray Tracing in One Weekend

Thanks, I'll look at this one too.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



One of the guys who wrote PBRT is actually a goon who has posted in CoC before, I forget his name though.

Xerophyte
Mar 17, 2008

This space intentionally left blank

piratepilates posted:

One of the guys who wrote PBRT is actually a goon who has posted in CoC before, I forget his name though.

Greg Humphreys, yep. One of two goons I'm aware of who have an Academy Award.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

dantheman650 posted:

Anyone know of a good regular expressions tutorial? I'm working with Ruby and Python if it matters. Never used regular expressions before, so think something that starts from scratch.

http://www.regular-expressions.info/tutorial.html is pretty good, despite the .info tld.

TheresaJayne
Jul 1, 2011

piratepilates posted:

Physically Based Rendering is the most comprehensive one out there, even won a technical Oscar. Covers a lot of stuff and goes much deeper than your first raytracer but it also covers the basics in good explanations so you can probably use it as a reference while trying to make your own.

When I first made a raytracer years ago I just googled raytracer tutorials, which gives a real mixed bag but should be helpful to get bits and pieces of what's applicable to help you out.

i tried to do the free Course but ended up losing it as i didnt get the math.
(next course starts 1st May)
https://www.edx.org/course/computer-graphics-uc-san-diegox-cse167x-1

Amberskin
Dec 22, 2013

We come in peace! Legit!

taqueso posted:

Does anyone have a favorite 'babby's first raytracer' guide or book?

This edX course covers basic raytracing really well (and als openGL):

https://www.edx.org/course/computer-graphics-uc-san-diegox-cse167x-1#!

The instructor is quite a guru in the business, and it is easy to follow and enjoy.

E: ^^^ Beaten

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Amberskin posted:

This edX course covers basic raytracing really well (and als openGL):

https://www.edx.org/course/computer-graphics-uc-san-diegox-cse167x-1#!

The instructor is quite a guru in the business, and it is easy to follow and enjoy.

E: ^^^ Beaten

I could not follow that guy at all

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I want to force a HTTP request to a particular host timeout in order to test something. Any sort of iptables or hosts file trickery I can do to achieve that?

edit: This seemed to work: http://stackoverflow.com/a/904609/400503

fletcher fucked around with this message at 22:22 on Apr 1, 2016

mystes
May 31, 2006

fletcher posted:

I want to force a HTTP request to a particular host timeout in order to test something. Any sort of iptables or hosts file trickery I can do to achieve that?

edit: This seemed to work: http://stackoverflow.com/a/904609/400503
If you did need to use iptables, that's really easy, too; you just need to drop outgoing connections to the host.

mobby_6kl
Aug 9, 2009

by Fluffdaddy

Bob Morales posted:

I could not follow that guy at all

TheresaJayne posted:

i tried to do the free Course but ended up losing it as i didnt get the math.
(next course starts 1st May)
https://www.edx.org/course/computer-graphics-uc-san-diegox-cse167x-1
I basically remembered nothing about linear algebra and managed pass this course just fine. I think I only needed to look up some of the ray-object intersections outside the course, and that was in the PBRT book, actually.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Star War Sex Parrot posted:

I rather liked this book that I found a couple of months ago: Ray Tracing in One Weekend

How much does this text require the other ones he mentions? Thinking about maybe doing this while I'm traveling but if you have to look things up frequently it may not work so well.

Xerophyte
Mar 17, 2008

This space intentionally left blank

Star War Sex Parrot posted:

I rather liked this book that I found a couple of months ago: Ray Tracing in One Weekend

The third book in the series is apparently out, and also free for a few days. Might be worth checking out for anyone who liked the previous two.

TheresaJayne
Jul 1, 2011

Bob Morales posted:

I could not follow that guy at all

i couldnt get the math

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

TheresaJayne posted:

i couldnt get the math

You definitely want to become familiar with at least matrices before you start the course

22 Eargesplitten
Oct 10, 2010



Hopefully this is the right thread. It's a hardware question, but specifically for programming use. I'm looking at possibly getting a new processor. Do Eclipse or Visual Studio in particular, or any of the common compilers / interpreters in general get much out of 4 cores, or are 2 hyperthreaded cores at a higher clock more effective? I guess I'm also interested about Unity, UE4, and possibly Cryengine if they get their poo poo sorted out.

sarehu
Apr 20, 2007

(call/cc call/cc)

22 Eargesplitten posted:

Hopefully this is the right thread. It's a hardware question, but specifically for programming use. I'm looking at possibly getting a new processor. Do Eclipse or Visual Studio in particular, or any of the common compilers / interpreters in general get much out of 4 cores, or are 2 hyperthreaded cores at a higher clock more effective? I guess I'm also interested about Unity, UE4, and possibly Cryengine if they get their poo poo sorted out.

Compiling stuff benefits heavily from more processors, even from being distributed across machines. So it depends on the clock difference and maybe the workload. Hyperthreading is like a 10% gain, not too important. Compilation should be faster on quad core, but maybe not your single threaded unit tests. I'd go quad core, being a statically typed AOT compiled person, making likely assumptions about the clock difference.

22 Eargesplitten
Oct 10, 2010



Okay, thanks. I've only ever had dual cores, since i3s are usually $70-100 cheaper than i5s. I'll see if I can swing an i5.

lord funk
Feb 16, 2004

I'm wrapping up an iOS app that has always been slated to be open source. I've never hosted an open source app, so I was are some best practices.

My thoughts so far:

- Github seems like an okay place to host the project
- I don't really care if people contribute to the project or not
- If someone did want to contribute, how does that work? Like, do you get a notification that someone wants to push to the project?

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

lord funk posted:

- If someone did want to contribute, how does that work? Like, do you get a notification that someone wants to push to the project?

The usual way on GitHub is that they'll make a fork of your project, commit changes to that fork, and then submit a pull request to your project with those changes. Then you get a trouble-ticket-like system where you can talk about the changes, examine the file diffs, suggest alterations, and when you're happy you hit the accept button and the commits are added to your project.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
If it's not on Github it might as well not exist, so good call there.

TooMuchAbstraction covered the pull requests feature. You'll get email notifications by default, they tell you how to proceed (or back out gently), so you won't miss anything.

If you're lucky enough to get someone with a proven history of useful contributions, you can give them permission to push directly to your repository, thereby skipping the steps where they clone your repo and wait for you to accept a pull request. Or maybe you never bother doing this and stick to pull requests. Up to you.

lord funk
Feb 16, 2004

Thanks, that sounds straightforward.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

22 Eargesplitten posted:

Hopefully this is the right thread. It's a hardware question, but specifically for programming use. I'm looking at possibly getting a new processor. Do Eclipse or Visual Studio in particular, or any of the common compilers / interpreters in general get much out of 4 cores, or are 2 hyperthreaded cores at a higher clock more effective? I guess I'm also interested about Unity, UE4, and possibly Cryengine if they get their poo poo sorted out.

Yes - and it's common enough where big projects are used as compiler benchmarks for hardware. Think compiling Firefox or Chromium (Chrome) on Visual Studio

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Is there a name for a transmitted set of data where, in order to read any of its built in values correctly (including values not on a byte border), you have to swap every consecutive pair of bytes wholesale (ie swap bytes 0 and 1, 2 and 3, etc)? I just did this for some data I'm tearing my hair out at trying to read, and all of the numbers started making sense.

Made-up example: in the first 24 bits i was expecting an integer unsigned equaling 169,457--or 0x0295F1. In the file the first four bytes are 0x9502xxF1, where xx is arbitrary--swap bytes 0/1 and 2/3, and I get the number I expected. If it were just little endian it'd be in the file as 0xF19502xx, so... what the gently caress?

:psyduck:

JawnV6
Jul 4, 2004

So hot ...

Ciaphas posted:

Is there a name for a transmitted set of data where, in order to read any of its built in values correctly (including values not on a byte border), you have to swap every consecutive pair of bytes wholesale (ie swap bytes 0 and 1, 2 and 3, etc)? I just did this for some data I'm tearing my hair out at trying to read, and all of the numbers started making sense.

Made-up example: in the first 24 bits i was expecting an integer unsigned equaling 169,457--or 0x0295F1. In the file the first four bytes are 0x9502xxF1, where xx is arbitrary--swap bytes 0/1 and 2/3, and I get the number I expected. If it were just little endian it'd be in the file as 0xF19502xx, so... what the gently caress?
Endianness is the right term. From wikipedia:

quote:

Mixed forms also exist, for instance the ordering of bytes in a 16-bit word may differ from the ordering of 16-bit words within a 32-bit word. Such cases are sometimes referred to as mixed-endian or middle-endian. There are also some bi-endian processors that operate in either little-endian or big-endian mode.
I use the term "swizzle" for any arbitrary byte shuffling that lacks a concise name. I think it's from graphics.

I'm sorta assuming "including values not on a byte border" you mean word, or are there actual cases where you're swapping nybbles around?

Adbot
ADBOT LOVES YOU

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
My favorite endianness story was decoding the images from a scientific camera. The (grayscale) pixel values had 12 bits of depth and were encoded into 16 bits, with the following structure:
code:
high 8 bits | low 4 bits, high 4 bits | low 8 bits | high 8 bits | etc.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply