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
Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Yeah, I've used TFS, too and I have a big list of things I don't like about it, but I do like the way it handles merge operations, even if the diff tool itself isn't good.

Funny I picked today to die on this dumb hill because now I'm looking at merging 300 lines into a test file that someone else also updated with 250 of their own and I'd really like to just run mine and see which tests are still working so I can throw out the failing ones that are just "x should call y" because they're probably just not valid anymore but now of course the file doesn't just run because git shat in it :sigh:

Adbot
ADBOT LOVES YOU

JawnV6
Jul 4, 2004

So hot ...
The terrible workflow I degenerate into when I've had terrible merges is to clone the repo somewhere else and git diff against that path.

Just checkout your (--ours) file in if that's what you want to run.

Obsurveyor
Jan 10, 2003

Munkeymon posted:

Funny I picked today to die on this dumb hill because now I'm looking at merging 300 lines into a test file that someone else also updated with 250 of their own and I'd really like to just run mine and see which tests are still working so I can throw out the failing ones that are just "x should call y" because they're probably just not valid anymore but now of course the file doesn't just run because git shat in it :sigh:

So revert to your branch and run yours? Unless you're saying you just want git to just automerge what it can and throw away the rest.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
If you just want the merge-in-progress files to be dumped in a different directory for whatever reason, recent versions of git support having multiple worktrees for a single repo, which probably makes that possible.

fritz
Jul 26, 2003

TooMuchAbstraction posted:

I'd think that'd result in the sewage output line from the toilet being 6" to the left of the waste pipe that leads to the civic sewage line.

All your windows different shapes and your stairs insulated.

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

fritz posted:

All your windows different shapes and your stairs insulated.

Every codebase more than a few years old is Groverhaus, really.

fritz
Jul 26, 2003

TooMuchAbstraction posted:

Every codebase more than a few years old is Groverhaus, really.

Every time you push your own code without review, you become a little more Grover.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Munkeymon posted:

Yeah, I've used TFS, too and I have a big list of things I don't like about it, but I do like the way it handles merge operations, even if the diff tool itself isn't good.

Funny I picked today to die on this dumb hill because now I'm looking at merging 300 lines into a test file that someone else also updated with 250 of their own and I'd really like to just run mine and see which tests are still working so I can throw out the failing ones that are just "x should call y" because they're probably just not valid anymore but now of course the file doesn't just run because git shat in it :sigh:

If it shat because of a merge, you can probably git reset --merge and get back to where you started.

It actually sounds like most of your issue with Git is the interface, specifically the CLI. Only a maniac would say Git has a good CLI. On the plus side, Git is full-featured enough that there's a way to work your way back from most dead ends, even if the solution is neither intuitive nor discoverable.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
How do I parameterize a GET request coming from Angular's $http, a developer might ask.

A developer might read the documentation or even google it, and find out that you can:
code:
$http.get('/api/endpoint',{params:{foo: 'bar'}})
A developer MIGHT do these things.

Or you might do this:

WebAPIConfig:
code:
config.Routes.MapHttpRoute(
	name: "ActionApiOneParam",
	routeTemplate: "api/{controller}/{action}/{param1}",
	defaults: new {param1 = RouteParameter.Optional}
);

config.Routes.MapHttpRoute(
	name: "ActionApiTwoParam",
	routeTemplate: "api/{controller}/{action}/{param1}/{param2}",
	defaults: new {param1 = RouteParameter.Optional, param2 = RouteParameter.Optional}
);
Until you've covered every single possible number of parameters.

Cuntpunch fucked around with this message at 21:28 on Apr 8, 2016

EkardNT
Mar 31, 2011
They used a for loop at least... right? :ohdear:

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

EkardNT posted:

They used a for loop at least... right? :ohdear:

Nope, at the start, we have 1, 2, and 4 param versions - but not 3, because they haven't yet run into a case where the API needed a 3 parameter endpoint :v:

I'm also trying to understand how this is going to impact our *non* insane WebAPI endpoints.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Cuntpunch posted:

Nope, at the start, we have 1, 2, and 4 param versions - but not 3, because they haven't yet run into a case where the API needed a 3 parameter endpoint :v:

Are you sure they weren't trying to prank you into searching the codebase for it?

Polio Vax Scene
Apr 5, 2009



Label your argument lists 1, 2, and 4 and set them loose in the repository. The other developers will wonder where the 3 argument list is hidden.

JawnV6
Jul 4, 2004

So hot ...
I'd just assume it was one hot.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

Cuntpunch posted:

How do I parameterize a GET request coming from Angular's $http, a developer might ask.

A developer might read the documentation or even google it, and find out that you can:
code:
$http.get('/api/endpoint',{params:{foo: 'bar'}})
A developer MIGHT do these things.

Or you might do this:

WebAPIConfig:
code:
config.Routes.MapHttpRoute(
	name: "ActionApiOneParam",
	routeTemplate: "api/{controller}/{action}/{param1}",
	defaults: new {param1 = RouteParameter.Optional}
);

config.Routes.MapHttpRoute(
	name: "ActionApiTwoParam",
	routeTemplate: "api/{controller}/{action}/{param1}/{param2}",
	defaults: new {param1 = RouteParameter.Optional, param2 = RouteParameter.Optional}
);
Until you've covered every single possible number of parameters.

This kind of thing wouldn't matter if the API server published those route definitions, but I'm guessing people typically write them by hand. To me, that's the horror.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Factor Mystic posted:

This kind of thing wouldn't matter if the API server published those route definitions, but I'm guessing people typically write them by hand. To me, that's the horror.

Mayyyyyyyybe. But even in reading the API endpoint code is a mess:

code:
public Endpoint(int param1, string param2, DateTime param3, DateTime param4)
{
	///Does things?
}
I mean it's just so kind of silly to do it that way, when considering that it's done *by hand* and all because someone didn't bother to either read the angular documentation around $http, google to a stack overflow post, or just *ask someone familiar with the tech* how they should parameterize a GET request.

Because outside even that as a *config* point, it's a little offputting to me that - lets say you're checking the price of gas on a given date for a given area
GET /api/gas/price?date=2016-04-08&zip=12345
or
GET /api/gas/price/2016-04-08/12345

DOUBLY so that they could *still* do the latter with direct endpoint method decoration([Route("{date:DateTime}/{zip:int}")]) instead of standing up some catchall rules that could inadvertantly blow up other API endpoints and using completely generic names aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

Cuntpunch posted:

How do I parameterize a GET request coming from Angular's $http, a developer might ask.

A developer might read the documentation or even google it, and find out that you can:
code:
$http.get('/api/endpoint',{params:{foo: 'bar'}})
A developer MIGHT do these things.

Or you might do this:

WebAPIConfig:
code:
config.Routes.MapHttpRoute(
	name: "ActionApiOneParam",
	routeTemplate: "api/{controller}/{action}/{param1}",
	defaults: new {param1 = RouteParameter.Optional}
);

config.Routes.MapHttpRoute(
	name: "ActionApiTwoParam",
	routeTemplate: "api/{controller}/{action}/{param1}/{param2}",
	defaults: new {param1 = RouteParameter.Optional, param2 = RouteParameter.Optional}
);
Until you've covered every single possible number of parameters.

In fairness, aren't these different things? $http get with params sends a query string, whereas that webapi stuff parameterizes the route?

So Angular is sending api/endpoint?foo=bar, the routes are api/endpoint/foo/bar or w/e

ed - beaten by the guy above me. I'll note for the record that if you casually google 'REST API endpoint design' or the such, route parameter binding (even for GETs) seems to be recommended everywhere.

Carbon dioxide
Oct 9, 2012

This week, I learned about code that should not be in mortal hands.

I am talking about sun.misc.Unsafe. This is a Java class that allows for a whole bunch of things that are normally not possible at all in Java. It's mostly used by internal Java methods for performance reasons. Have an example use of Unsafe:

Java code:
class DirectIntArray {
 
  private final static long INT_SIZE_IN_BYTES = 4;
 
  private final long startIndex;
 
  public DirectIntArray(long size) {
    startIndex = unsafe.allocateMemory(size * INT_SIZE_IN_BYTES);
    unsafe.setMemory(startIndex, size * INT_SIZE_IN_BYTES, (byte) 0);
    }
  }
 
  public void setValue(long index, int value) {
    unsafe.putInt(index(index), value);
  }
 
  public int getValue(long index) {
    return unsafe.getInt(index(index));
  }
 
  private long index(long offset) {
    return startIndex + offset * INT_SIZE_IN_BYTES;
  }
 
  public void destroy() {
    unsafe.freeMemory(startIndex);
  }
}
 
@Test
public void testDirectIntArray() throws Exception {
  long maximum = Integer.MAX_VALUE + 1L;
  DirectIntArray directIntArray = new DirectIntArray(maximum);
  directIntArray.setValue(0L, 10);
  directIntArray.setValue(maximum, 20);
  assertEquals(10, directIntArray.getValue(0L));
  assertEquals(20, directIntArray.getValue(maximum));
  directIntArray.destroy();
}
This class creates an array of integers in native (non-heap) memory. To be specific, a normal Java array can't have more elements than Integer.MAX_VALUE. Unsafe has no limits. This test method creates an 8192MB array, so make sure you have plenty of memory.

Some of the other things you can do with Unsafe:
  • Write stuff directly to memory addresses, without any range checks or any protection against memory corruption
  • Instantiate objects without ever calling their constructor
  • Having a method throw a checked Exception without declaring it.
Now, sun.misc.Unsafe has a check that makes it impossible to call it from outside the native Java stuff. Except, that check is poorly implemented. With a little Reflection trick, you can easily get a reference to an instance. Once someone figured that out, a whole bunch of third party frameworks and libraries started using it. I heard the popular Spring framework is one of them.

The reason I heard about this is because they're changing stuff about this class in Java 9, which will have its official release in March 2017. I am not completely sure what will happen. The person who talked about it while giving a presentation about Java 9 said they're locking it down completely, which means that all those libraries will need to be updated. But some (somewhat older) webpage says that Oracle was thinking about making a public API for it.

Source of my example, with a bunch of other examples: https://dzone.com/articles/understanding-sunmiscunsafe

Carbon dioxide fucked around with this message at 10:19 on Apr 9, 2016

feedmegin
Jul 30, 2008

Um. If true doesnt that make the sandbox totally worthless for security? Can you call this stuff in an applet?

Carbon dioxide
Oct 9, 2012

feedmegin posted:

Um. If true doesnt that make the sandbox totally worthless for security? Can you call this stuff in an applet?

I am not sure. But I assume it works something like this. The JVM uses a certain part of memory. Within the JVM, this is basically divided into three parts: native, stack and heap. The stack has primitive variables and pointers to the heap, while the heap holds Java objects.

Native memory is used for low-level java/JVM-internal stuff that normally cannot be reached with java code. Unsafe allows you to put an object into this native memory but the JVM cannot recognize it as an object unless you use Unsafe again to specifically read it as an object. The JVM can also allocate free native memory to the heap in order to expand the heap.

But all of this native, stack and heap memory exists within the JVM. It's a division of memory that only makes sense within the Java Virtual Machine. The JVM itself lives in the true heap memory of the machine it runs on. So it's not like you get access to the real machine's native memory. Security is still fine.

Someone correct me if I'm wrong, I'm not much of an expert on this low-level stuff.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

feedmegin posted:

Um. If true doesnt that make the sandbox totally worthless for security? Can you call this stuff in an applet?

No, the sun.* packages are inaccessible to applets.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

uncurable mlady posted:

In fairness, aren't these different things? $http get with params sends a query string, whereas that webapi stuff parameterizes the route?

So Angular is sending api/endpoint?foo=bar, the routes are api/endpoint/foo/bar or w/e

ed - beaten by the guy above me. I'll note for the record that if you casually google 'REST API endpoint design' or the such, route parameter binding (even for GETs) seems to be recommended everywhere.

And the very first hit on Google immediately dives into the fact that Filtering via querystring(and the second, and third, and fourth) is how to do filtering on a REST api :v:. Because querystring parameters and REST are not some sort of opposing topics. Perhaps abstracting out the param to foo=bar was too much?

Imagine I've got a service that looks up census data. I can either
GET /api/people?bornafter=2001-09-11&stillalive=true

or

GET /api/people/2001-09-11/true

One of these APIs self-documents and the other does not.

Workaday Wizard
Oct 23, 2009

by Pragmatica
I explicitly assign the endpoint url for every controller method i have using Route decorator. Am I the horror?

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Shinku ABOOKEN posted:

I explicitly assign the endpoint url for every controller method i have using Route decorator. Am I the horror?

Compared to what? That's what I would *expect* at least in WebAPI land.

On a given controller, I tend to RoutePrefix the baseline("/api/type")

Then excepting the stuff that will work against that *specific* endpoint(generally just GET!) I like to explicitly declare both the expected Route and the verb

[Route("{typeId:int}")]
[HttpPut]

[Route("{typeId:int}/subtype")]
[HttpGet]

or similar - rather than setting up comedy catchall rule in the global config, and using method names to *infer* the expected verb.(PutType(), GetType(), PatchType()) etc.

Workaday Wizard
Oct 23, 2009

by Pragmatica

Cuntpunch posted:

Compared to what?

Every tutorial and template I could find. I think even the official MSDN tutorial uses the blanket route map.

Impotence
Nov 8, 2010
Lipstick Apathy

Cuntpunch posted:

And the very first hit on Google immediately dives into the fact that Filtering via querystring(and the second, and third, and fourth) is how to do filtering on a REST api :v:. Because querystring parameters and REST are not some sort of opposing topics. Perhaps abstracting out the param to foo=bar was too much?

Imagine I've got a service that looks up census data. I can either
GET /api/people?bornafter=2001-09-11&stillalive=true

or

GET /api/people/2001-09-11/true

One of these APIs self-documents and the other does not.

i've actually seen something like this before
/api/people/by-date/since/exists/2001/09/11/by-status/alive?offset=x

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

Cuntpunch posted:

And the very first hit on Google immediately dives into the fact that Filtering via querystring(and the second, and third, and fourth) is how to do filtering on a REST api :v:. Because querystring parameters and REST are not some sort of opposing topics. Perhaps abstracting out the param to foo=bar was too much?

Imagine I've got a service that looks up census data. I can either
GET /api/people?bornafter=2001-09-11&stillalive=true

or

GET /api/people/2001-09-11/true

One of these APIs self-documents and the other does not.

i mean you're not wrong, i'm just telling you what i've seen in terms of 'api design' from the more node/flask side of things i guess. /shrug

FamDav
Mar 29, 2008

Biowarfare posted:

i've actually seen something like this before
/api/people/by-date/since/exists/2001/09/11/by-status/alive?offset=x

Can this be the new thread title.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Biowarfare posted:

i've actually seen something like this before
/api/people/by-date/since/exists/2001/09/11/by-status/alive?offset=x

:suicide:

dc3k
Feb 18, 2003

what.

FamDav posted:

Can this be the new thread title.

Please yes. That is terrifying.

Eleeleth
Jun 21, 2009

Damn, that is one suave eel.

Biowarfare posted:

i've actually seen something like this before
/api/people/by-date/since/exists/2001/09/11/by-status/alive?offset=x

I bet they claimed this poo poo was RESTful too.

Impotence
Nov 8, 2010
Lipstick Apathy

Eleeleth posted:

I bet they claimed this poo poo was RESTful too.

rest, hateoas, and only supports GET, no put/patch/post/delete

edit: you can update user records with something like GET /api/people/ceffc1ed-436b-4acc-83c0-6a2051f0d5ce/update?fieldname=newvalue

Space Kablooey
May 6, 2009


Biowarfare posted:

edit: you can update user records with something like GET /api/people/ceffc1ed-436b-4acc-83c0-6a2051f0d5ce/update?fieldname=newvalue

I give up. :suicide:

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings
Am I.....missing something?

code:
	var CurrentDate = DateTime.Now.ToString("MM-dd-yyyy");
	var date = DateTime.ParseExact(CurrentDay, "MM-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture);

nielsm
Jun 1, 2009



Cuntpunch posted:

Am I.....missing something?

code:
	var CurrentDate = DateTime.Now.ToString("MM-dd-yyyy");
	var date = DateTime.ParseExact(CurrentDay, "MM-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture);

I think they want a DateTime that represents the day without a time-of-day component.

There has to be a better way to do that...

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

nielsm posted:

I think they want a DateTime that represents the day without a time-of-day component.

There has to be a better way to do that...

In a single line?
code:
DateTime.Now.Date

ninjeff
Jan 19, 2004

Cuntpunch posted:

In a single line?
code:
DateTime.Now.Date

code:
DateTime.Today

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

ninjeff posted:

code:
DateTime.Today

Even better :v:

TheresaJayne
Jul 1, 2011
I was looking for the link somewhere in this thread for the Classname quiz that uses the silly Spring class names and you have to select the real one from the made up ones.


ie AbstractSingletonProxyFactoryBean

Adbot
ADBOT LOVES YOU

ErIog
Jul 11, 2001

:nsacloud:

TheresaJayne posted:

I was looking for the link somewhere in this thread for the Classname quiz that uses the silly Spring class names and you have to select the real one from the made up ones.


ie AbstractSingletonProxyFactoryBean

http://bfy.tw/5DuV

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