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
Fergus Mac Roich
Nov 5, 2008

Soiled Meat

JawKnee posted:

what technology uses an '@' prefix to signify embedded code?

If by "embedded code" you mean "code embedded within this file" rather than "code running on embedded platforms", powershell uses @ for heredocs.

Adbot
ADBOT LOVES YOU

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
sorry I'm probably using the wrong terms - I mean code that is going to be running on a server rather than locally

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
C# uses an @ prefix on strings to turn off backslash-escaping, which is useful if you're writing SQL or the like in strings.

If that's not it, and you have an example of what you're trying to find out about, could you just post it? It'd be way easier than us trying to divine just wtf you're talking about.

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
The code is at my work and I'm at home, so I don't have anything I can copy-paste for you, my apologies. It's a new job and I'm not terribly familiar with most of the technologies being used - C#, SQL, LINQ, typescript, JQuery, and others that I'm forgetting.

I'm familiar with verbatim strings though, and this isn't it. I've mainly seen it being used in front of using directives, if-blocks, for-loops, and other statements that are otherwise C# code - but not used as a prefix for html or javascript.

e: I think I've found it - it's part of the Razor syntax for ASP.NET

JawKnee fucked around with this message at 07:14 on Apr 27, 2018

Volguus
Mar 3, 2009

JawKnee posted:

The code is at my work and I'm at home, so I don't have anything I can copy-paste for you, my apologies. It's a new job and I'm not terribly familiar with most of the technologies being used - C#, SQL, LINQ, typescript, JQuery, and others that I'm forgetting.

I'm familiar with verbatim strings though, and this isn't it. I've mainly seen it being used in front of using directives, if-blocks, for-loops, and other statements that are otherwise C# code - but not used as a prefix for html or javascript.

e: I think I've found it - it's part of the Razor syntax for ASP.NET

That looks like old asp and jsp pages.

Munkeymon
Aug 14, 2003

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



Volguus posted:

That looks like old asp and jsp pages.

ASP only uses @s in the directives you'd see at the top of the file, so I understand why you'd get that impression: you open the file, recognize it's ASP and close it immediately without looking at the rest because that's the rational thing to do. It uses <% and %> for open/close tags (and I think maybe optionally <? and ?> because they were competing mainly with PHP when they made the spec). Source: I maintain ASP at current job :smith:

Volguus
Mar 3, 2009

Munkeymon posted:

ASP only uses @s in the directives you'd see at the top of the file, so I understand why you'd get that impression: you open the file, recognize it's ASP and close it immediately without looking at the rest because that's the rational thing to do. It uses <% and %> for open/close tags (and I think maybe optionally <? and ?> because they were competing mainly with PHP when they made the spec). Source: I maintain ASP at current job :smith:

Right, but there doesn't seem to be a difference between this @{} and <% %> (in either asp or jsp). Is the same hat just a different color.

Munkeymon
Aug 14, 2003

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



Volguus posted:

Right, but there doesn't seem to be a difference between this @{} and <% %> (in either asp or jsp). Is the same hat just a different color.

Sure, it's a templating language that lets you embed code, so it's going to be pretty similar. The Razor syntax is odd, at least among templating languages that I'm familiar with, in that it just makes you mark the beginning of code with the @ character and only makes you explicitly mark the end with a } if it's ambiguous where you intend it to end. Control flow is the main case for that, but you can still write stuff like

code:
@foreach (var person in model.people) {
   var greeting = $"Hello {person.name}"; //still code
   <p>@greeting</p> <!- now it's markup ->
   <p>@hello(person.name);</p>
   <p>@person.name has been greeted twice, but the second ended with a visible ;</p>
}
Where markup is mixed right into what looks like a code block and it usually just works because the angle brackets in HTML are a good indicator of where markup starts. In the case of the method call, 'code' ends with the closing paren, so it renders the semicolon because it's text. Most transitions from code to markup or markup to code don't require special braces, which distinguishes it from pretty much any other templating language I'm familiar with.

e: I guess JSX comes close, but you still need to enclose code in braces once you've gone into a template block

Munkeymon fucked around with this message at 14:44 on Apr 27, 2018

mila kunis
Jun 10, 2011
The functional programming thread seems to be closed, so I thought i'd ask here. Is there a mooc/any kind of resource that's as good at explaining it as Functional programming in Scala but in another language? I don't want to deal with installing Eclipse/the JVM and all that crap, just learn the fundamental principles.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

tekz posted:

The functional programming thread seems to be closed, so I thought i'd ask here. Is there a mooc/any kind of resource that's as good at explaining it as Functional programming in Scala but in another language? I don't want to deal with installing Eclipse/the JVM and all that crap, just learn the fundamental principles.

You just want a non-scala "how to functional" thing?

F# for fun and profit has a lot of material, that section's about thinking functionally but there's a lot more, like stuff about design and patterns. He avoids talking about whether a monad is like tacos but still gets into that stuff if you want to go deeper

(If you actually want to use F# you can just use the Ionide extension with VS Code or Atom)

Or if you don't want to install anything, apparently the Elm tutorials are good and work in yr browser?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


tekz posted:

The functional programming thread seems to be closed, so I thought i'd ask here. Is there a mooc/any kind of resource that's as good at explaining it as Functional programming in Scala but in another language? I don't want to deal with installing Eclipse/the JVM and all that crap, just learn the fundamental principles.

There was a very good OCaml mooc that would be worth taking if it's ever offered again.

User
May 3, 2002

by FactsAreUseless
Nap Ghost

baka kaba posted:

You just want a non-scala "how to functional" thing?

F# for fun and profit has a lot of material, that section's about thinking functionally but there's a lot more, like stuff about design and patterns. He avoids talking about whether a monad is like tacos but still gets into that stuff if you want to go deeper

(If you actually want to use F# you can just use the Ionide extension with VS Code or Atom)

Or if you don't want to install anything, apparently the Elm tutorials are good and work in yr browser?

Don't forget Racket! http://racket-lang.org/

edmund745
Jun 5, 2010
I am trying to use TortiseHG..... I think?

I had this installed for a long time to track projects on my own PC (no remote server). Back then I found--or was told of--a website that had plain-English instructions for setting it up to work on your own PC< with no remote servers. And it worked perfectly, for a long time.

I got a new PC and installed the current version, and it has a couple things that it won't do right, and I can't find any useful instructions online.
The version I have says version 2.8.1 with Mercurial-2.6.2, Python-2.7.3, PyQt-4.9.6, Qt-4.8.4

There should be an image immediately below:


1) This new version keeps leaving the previous commit messages here. Where is the setting to not do that? Or what is it called, so I can Google it myself? I have not been able to find it.

2) This dialog pops up on every commit, that seems to indicate an error? How do I get rid of that? (considering that I have no remote servers at all?) I can't find any instructions for what to do if you aren't using any remote server? None of the sites I've found that say how to use it, say how to do that.

It still does the commits, and all the file changes and commit messages are there. It's just these two problems I can't find out how to fix.

Lastly, not pictured:
3) Did TortiseHG change its name to TortiseGIT? Because in the past there was tons of instructions online for TortiseHG (most of which seemed to be just copies of each other, but anyway).
Now when I search Google for TortiseHG, mostly what it finds is lots and lots of pages about something named TortiseGIT....

nielsm
Jun 1, 2009



The screenshot says you have an option selected "--pushafter=default", it seems to try to push to a remote, but since you don't have a remote but are only working locally, that fails. So change your commit options to not try to push.

Most people now prefer the Git version control system over Mercurial, so it's sort of natural that you'll see more references to that.

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE
edit: I'll ask elsewhere

Paul MaudDib fucked around with this message at 00:10 on May 1, 2018

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Don't really know of a better place to ask this...

How well does the PDF format handle minor corruption? Say you copy a PDF to a flash drive that unbeknownst to you is a little dodgy and the PDF ends up with a few bit flips or something.

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Thermopyle posted:

Don't really know of a better place to ask this...

How well does the PDF format handle minor corruption? Say you copy a PDF to a flash drive that unbeknownst to you is a little dodgy and the PDF ends up with a few bit flips or something.

Depending on where the errors are, the results can range from trivial to unrecoverable. Really no way to know, but there are a number of damaged pdf repair tools (including part of just Acrobat itself).

sofokles
Feb 7, 2004

Fuck this
prolly incorrect place but whatever

I want to highlight text -

| in win
|| on iphone
||| in firefox, edge or chrome

and be able to choose "Search Spotify" or "Search Tidal"

as I don't care about YouTube or Apple Music

Doable ?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I’m not sure I understand, but assuming I do:

On iOS your best bet may be something like Workflow. You’d make a workflow that takes text as input, urlescapes it, splices it into a URL, then opens that URL. Could be an http URL for searching the services you want, or if you’re lucky the apps might have implemented a custom URL scheme and/or Universal Links. To use, just select some text, choose Share from the menu, pick Run Workflow, and choose the workflow. Not exactly one-click but it should work.

For browsers your best bet is probably a bookmarklet and/or extension. Maybe you write the extension or maybe you write a script that runs in some user script extension thinger.

Not sure about Windows, will leave that to someone else.

Dominoes
Sep 20, 2007

Hey dudes. Not sure if this is the right place.

I'm trying to create a basic 3d rendering engine. My intent is to create a 4d projection onto 2d space, but starting with 3d; hence wheel reinvention. I'm using Rust. I set up a system to create simple 3d (or 4d...) shapes, placed where I'd like in 3d (...) space. By simply using the matrices defined in this Wikipedia article under 'Perspective Projection', I got a basic 3d projection.

I can move around this little world, but rotating seems to rotate the scene around the origin, rather than like a FPS camera, which is what I'm going for. (Confusing, since Wikipedia defines the θ I'm adjusting to be camera orientation.) I did some more digging; found this article, which seems to stop right where it should show the transform I'm looking for. Simply subbing the 'FPS camera' matrix defined there instead of the Wiki art's Camera Transform matrix produces weird results when I rotate.

This article talks mostly about moving your 3d models into a single coord system, which the Rust funcs I made do automatically, AFAIK; ie they accept a position as an input arg. It then handwaves the real transformation by saying the GPU does it.

I have a feeling the answer is to review my lin alg and figure it out... I'll likely have to do that anyway when it comes to the 4d -> 2d projection I'm ultimately shooting for. Any resources that would help?

Code that produces the rotate-around-origin projection:
Rust code:
fn camera_transform_3d(cam: &Camera, node: &Node) -> Array1<f64> {
    // Perform a camera transform; define a vector d as the position
    // of point A with respect to the coordinate system defined by 
    // the camera, with origin in C and rotated by &#952; with respect
    // to the initial coordinate system.

    // Split the transform constructor into three parts to make it
    // easier to read and write.
    let D_0 = array![
        [1., 0., 0.],
        [0., cam.theta[0].cos(), cam.theta[0].sin()],
        [0., -cam.theta[0].sin(), cam.theta[0].cos()]
    ];

    let D_1 = array![
        [cam.theta[1].cos(), 0., -cam.theta[1].sin()],
        [0., 1., 0.],
        [cam.theta[1].sin(), 0., cam.theta[1].cos()]
    ];

    let D_2 = array![
        [cam.theta[2].cos(), cam.theta[2].sin(), 0.],
        [-cam.theta[2].sin(), cam.theta[2].cos(), 0.],
        [0., 0., 1.]
    ];

    let D = D_0.dot(&(D_1.dot(&D_2)));

    D.dot(&(&node.a - &cam.c))
}

fn project_3d(cam: &Camera, node: &Node) -> Node {
    // Project a 3d node onto a 2d plane.
    // [url]https://en.wikipedia.org/wiki/3D_projection[/url]

    let d = camera_transform_3d(cam, node);

    let A = array![
        [1., 0., -cam.e[0] / cam.e[2], 0.],
        [0., 1., -cam.e[1] / cam.e[2], 0.],
        [0., 0., 1., 0.],
        [0., 0., -1. / cam.e[2], 1.],
    ];

    let f = A.dot(
        &array![d[0], d[1], d[2], 1.]
    );

    // Keep the original node's id, but transform its position to 2d space.
    Node {a: array![&f[0] / &f[3], &f[1] / &f[3]], id: node.id}
}

Dominoes fucked around with this message at 20:35 on May 5, 2018

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
First rule of computer graphics: you are at the origin.

Think of the camera not as an object that moves around the world and pivots, but as a force that slides objects to and from the origin, and rotates objects around the origin. They are mathematically equivalent, of course, but in your head they "feel" quite different. And in that mental image, what, mind you, gives you the desired effect?

You have two options: I can, first, rotate the objects around the origin first, and then slide them into place, or I can slide them into place and then rotate around the origin.

Think carefully about which transformation needs to happen first, and which needs to happen second. This should help resolve your issue.

Dominoes
Sep 20, 2007

You're spot on that I was visualizing the system as moving and rotating the camera around a static coord system. Looks like with that outlook changed, the Wikipedia transform might work after all... Maybe causing the translations to shift every node's coordinates prior to the cam transform rather than moving the cam location (&cam.c in the function I defined above).'


edit... May have to offset for what Wiki defines as e... a variable that's related to FOV and the perspective. By doing what I described (you implied) above, the rotation center now translates with the camera, but is always a fixed dist behind the view. I think if I can rotate e by the camera angle, and subtract that from the rotation transform I posted above, I can cause the view to be coincident with the rotation point, without breaking the perspective...

Dominoes fucked around with this message at 21:57 on May 5, 2018

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

Dominoes posted:

Hey dudes. Not sure if this is the right place.

I'm trying to create a basic 3d rendering engine. My intent is to create a 4d projection onto 2d space, but starting with 3d; hence wheel reinvention. I'm using Rust. I set up a system to create simple 3d (or 4d...) shapes, placed where I'd like in 3d (...) space. By simply using the matrices defined in this Wikipedia article under 'Perspective Projection', I got a basic 3d projection.

Cool project. Just remember rotations if 4D are vastly more complicated than in 3D. There's no axis of rotation for example. There's a decent intro at SO(4) but expect to brush up on your linear algebra.

I'm excited to see how this turns out though.

Dominoes
Sep 20, 2007

KernelSlanders posted:

Cool project. Just remember rotations if 4D are vastly more complicated than in 3D. There's no axis of rotation for example. There's a decent intro at SO(4) but expect to brush up on your linear algebra.

I'm excited to see how this turns out though.
It looks like this site has One of multiple ways to define 4d rotation matrices solved for, but I don't understand it yet. I think I have everything doped for the 3d renderer, other than getting the viewpoint to be colocated with the origin of rotation. The FPS-style controls are still a bit wonky, but I think that's related. (I just dotted the 3d rotation matrices with unit vectors in each of the 6 directions for movement). Once this is solved, I can tackle the 4d transforms.

Dominoes fucked around with this message at 17:59 on May 6, 2018

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Dominoes posted:

You're spot on that I was visualizing the system as moving and rotating the camera around a static coord system. Looks like with that outlook changed, the Wikipedia transform might work after all... Maybe causing the translations to shift every node's coordinates prior to the cam transform rather than moving the cam location (&cam.c in the function I defined above).'


edit... May have to offset for what Wiki defines as e... a variable that's related to FOV and the perspective. By doing what I described (you implied) above, the rotation center now translates with the camera, but is always a fixed dist behind the view. I think if I can rotate e by the camera angle, and subtract that from the rotation transform I posted above, I can cause the view to be coincident with the rotation point, without breaking the perspective...

There are two parts here: the perspective and FOV part is known as the "projection" matrix, and that's a non-linear transformation that involves that pesky divide-by-W bit. The rest of it is affine transformations (linear + translation) and can rotate, scale, and translate. Traditionally, this part of the camera transformation is known as the "eye" or "view" part, which translates from world-space to eye-space (sometimes called view-space). Ignore this part for now.

Objects themselves can also do things like rotating in place and this is known as the "model" matrix, which translates from object-space to world-space. If you have a rotating cube that you want to stare at, then you have 1. the cube rotating, 2. the cube translated to be somewhere in world-space, 3. a translation that puts the camera's location at the origin, 4. a rotation about the origin that points the camera where you want it.

This set of transformations is often known as the "model-view" transformation (no relation to the "model" and "view" of "model view controller", waddya know, programmers are terrible at naming things), and can be expressed in one 4x3 matrix as a single transformation from object space to view space.

After the view-space transformation comes the projective transformation, which (traditionally) turns you from a linear space where parallel lines never intersect to a projective space where parallel lines intersect at infinity. If you have an orthographic view, you don't need it (though a projection matrix is used for other features in a "real" 3d scenario like depth remap)

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
As for FPS controls, WASD is pretty clear (just multiply your camera matrix by a translation matrix to move in space). For rotation like mouselook, the easiest way to do that is to rotate X around your camera's up vector, and then rotate Y around your world-space right axis. This is not correct if you have any bank rotation, but I don't know if there is a convention for what mouselook does when you have bank rotation applied -- it's kind of just a hosed concept.

JavaScript code:
        let mult = this.speed;
        if (inputManager.isKeyDownRaw(SHIFT))
            mult *= 5;
        mult *= (dt / 16.0);

        if (inputManager.isKeyDown('W'))
            tmp[14] = -mult;
        else if (inputManager.isKeyDown('S'))
            tmp[14] = mult;

        if (inputManager.isKeyDown('A'))
            tmp[12] = -mult;
        else if (inputManager.isKeyDown('D'))
            tmp[12] = mult;

        const cu = vec3.fromValues(camera[1], camera[5], camera[9]);
        vec3.normalize(cu, cu);
        mat4.rotate(camera, camera, -inputManager.dx / 500, cu);
        mat4.rotate(camera, camera, -inputManager.dy / 500, [1, 0, 0]);
        mat4.multiply(camera, camera, tmp);

SurgicalOntologist
Jun 17, 2004

I'm trying to parse an XML file created by a program I don't have access to. The first line is
code:
<?xml version='1.0' encoding='utf-8'?>
That appears to be correct for the first portion of the file, which essentially just contains metadata. Then the encoding seems to abruptly change partway through the first line of actual data. Running chardetect tells me
code:
windows-1253 with confidence 0.2865960665483076
So, trying to decode some lines manually, I can get the first 5 or 6 bytes of each line decoded as windows-1253 but that's it. And I just get some greek letters that I don't see any meaning in.

Is it likely this file has bee intentionally obfuscated or is there another explanation I'm missing? Any ideas on how to parse it?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

SurgicalOntologist posted:

I'm trying to parse an XML file created by a program I don't have access to. The first line is
code:
<?xml version='1.0' encoding='utf-8'?>
That appears to be correct for the first portion of the file, which essentially just contains metadata. Then the encoding seems to abruptly change partway through the first line of actual data. Running chardetect tells me
code:
windows-1253 with confidence 0.2865960665483076
So, trying to decode some lines manually, I can get the first 5 or 6 bytes of each line decoded as windows-1253 but that's it. And I just get some greek letters that I don't see any meaning in.

Is it likely this file has bee intentionally obfuscated or is there another explanation I'm missing? Any ideas on how to parse it?

Some people put binary data in xml streams (also JSON). It’s generally for data compression or ease of decoding into whatever custom serializer someone wrote, not obfuscation (same thing re: mixed character sets).

If you know what information is necessary, reverse engineering it is a bit easier. Assuming it’s not encrypted.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
That’s a pretty low confidence and the win-125X code pages define (almost?) every byte so I’m on board with the “probably encoded binary data” theory. Maybe split that portion out and run file on it?

redleader
Aug 18, 2005

Engage according to operational parameters

SurgicalOntologist posted:

Any ideas on how to parse it?

"Dear $vendor, your "xml" isn't. Please provide me with a version that can be understood by an actual XML parser"

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

redleader posted:

"Dear $vendor, your "xml" isn't. Please provide me with a version that can be understood by an actual XML parser"

“Dear $client; our internal file formats are for our use only and we do not allow reverse engineering our client or services. We are happy to provide assistance integrating into your applications at a daily rate of $xxxx”

Dominoes
Sep 20, 2007

Suspicious Dish posted:

As for FPS controls, WASD is pretty clear (just multiply your camera matrix by a translation matrix to move in space). For rotation like mouselook, the easiest way to do that is to rotate X around your camera's up vector, and then rotate Y around your world-space right axis. This is not correct if you have any bank rotation, but I don't know if there is a convention for what mouselook does when you have bank rotation applied -- it's kind of just a hosed concept.

JavaScript code:
        let mult = this.speed;
        if (inputManager.isKeyDownRaw(SHIFT))
            mult *= 5;
        mult *= (dt / 16.0);

        if (inputManager.isKeyDown('W'))
            tmp[14] = -mult;
        else if (inputManager.isKeyDown('S'))
            tmp[14] = mult;

        if (inputManager.isKeyDown('A'))
            tmp[12] = -mult;
        else if (inputManager.isKeyDown('D'))
            tmp[12] = mult;

        const cu = vec3.fromValues(camera[1], camera[5], camera[9]);
        vec3.normalize(cu, cu);
        mat4.rotate(camera, camera, -inputManager.dx / 500, cu);
        mat4.rotate(camera, camera, -inputManager.dy / 500, [1, 0, 0]);
        mat4.multiply(camera, camera, tmp);
Got the FPS controls and 3d projection working properly by using input patterns like those (Plus angle normalization (0 to τ) for Yaw/Roll, and hard caps on pitch -(τ/4 to τ/4)), and replacing Wiki's projection matrix with this:

Rust code:
let s = 1. / (cam.fov / 2. as f64).tan();

// near and far clipping planes
let f = 20.;
let n = 0.2;

let perspective_projection = array![
    [s, 0., 0., 0.],
    [0., s, 0., 0.],
    [0., 0., -f / (f-n), -1.],
    [0., 0., -f*n / (f-n), 0.]
];

let homogenous_pt = array![
    rotated_shifted_pt[0], 
    rotated_shifted_pt[1], 
    rotated_shifted_pt[2],
    1.
];

let f = perspective_projection.dot(&homogenous_pt);
// Divide by w to find the 2d projected coords.
let b = array![&f[0] / &f[3], &f[1] / &f[3]];

// Keep the original node's id, but transform its position to 2d space.
Node {a: b, id: node.id}
}
Just need to figure out how to solve clipping Probably with this, then ready to try 4d transforms.

Dominoes fucked around with this message at 00:36 on May 9, 2018

underage at the vape shop
May 11, 2011

by Cyrano4747
Why is this returning an empty string?If you print the values its getting them correctly.

code:
	public static String getList() {
		Titles.sort(String.CASE_INSENSITIVE_ORDER);
		String sorted = new String();	
		for (String name:Titles) {
				sorted.concat(name);
			}
		System.out.print(sorted);
			
	return sorted;
	}
This is in java

underage at the vape shop fucked around with this message at 08:07 on May 9, 2018

feedmegin
Jul 30, 2008

underage at the vape shop posted:

Why is this returning an empty string?If you print the values its getting them correctly.

code:
	public static String getList() {
		Titles.sort(String.CASE_INSENSITIVE_ORDER);
		String sorted = new String();	
		for (String name:Titles) {
				sorted.concat(name);
			}
		System.out.print(sorted);
			
	return sorted;
	}
This is in java

Check out concat's return value.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

underage at the vape shop posted:

Why is this returning an empty string?If you print the values its getting them correctly.

code:
	public static String getList() {
		Titles.sort(String.CASE_INSENSITIVE_ORDER);
		String sorted = new String();	
		for (String name:Titles) {
				sorted.concat(name);
			}
		System.out.print(sorted);
			
	return sorted;
	}
This is in java

Java Strings are immutable. Nothing ever changes a string in place. Using
code:
sorted = sorted.concat(name);
will work, but it creates a whole bunch of strings that are immediately discarded. The appropriate tool here is a StringBuilder.

Kruxy
May 19, 2004

Just a steel town girl on
a Saturday night, looking
for the fight of her life

I'm trying to put together a team roster thing for a page at work, but I am not a coder. I can (sometimes) figure out how to tweak existing code to make something do what I want. I'm working with this Collapsible Accordion code from w3schools, but I can't figure out if the problem I'm running into is a Javascript thing or a CSS thing -- or a mixture of the two.

When I open up the main accordion all of the sub accordions show up. But if I try to open up any sub accordions, text gets cut off because the main accordion has already determined how tall the column is going to be. If I close the main accordion and then reopen it, the column length has now adjusted to accommodate the extended text from the sub-accordion.

I need the main accordion to readjust the height as submenus are opened. If I change the overflow to show from hidden, the main menu adjusts height accordingly, but everything in the submenus is visible in the layer behind the menus.

The one big hitch is that I'm working with this proprietary collaboration software. It allows for HTML widgets (that will support CSS and Javascript) but it does not play nice with super complicated coding.

This is the w3schools code I'm working with. Any suggestions or help would be awesome.


code:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.accordion {
    background-color: #eee;
    color: #444;
    cursor: pointer;
    padding: 18px;
    width: 100%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 15px;
    transition: 0.4s;
}

.active, .accordion:hover {
    background-color: #ccc;
}

.panel {
    padding: 0 18px;
    background-color: white;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease-out;
}
</style>
</head>
<body>

<h2>Animated Accordion</h2>
<p>Click on the buttons to open the collapsible content.</p>

<button class="accordion">animated accordions</button>

<div class="panel">

<button class="accordion">Section 1</button>
<div class="panel">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

<button class="accordion">Section 2</button>
<div class="panel">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>

<button class="accordion">Section 3</button>
<div class="panel">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>

<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight){
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    } 
  });
}
</script>

</body>
</html>

Shaocaholica
Oct 29, 2002

Fig. 5E
How dumb/insecure is this.

You have a cloud based file storage service like dropbox or google drive. As an optimization, you store a huge dictionary of post encryption file size and payload hashes. So if 2 or more people have nickelback_song.mp3 but with different file names, the payload hash and file size should match and they can both just point to the same encrypted file even though their accounts have nothing to do with each other. Would that work in practice? Would it be bad for security even if its done post encryption?

My gut tells me there's a huge percentage of redundant 'public' data in cloud storage services. Maybe they've figured a better way to optimize the storage of redundant data across different user accounts.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Shaocaholica posted:

How dumb/insecure is this.

You have a cloud based file storage service like dropbox or google drive. As an optimization, you store a huge dictionary of post encryption file size and payload hashes. So if 2 or more people have nickelback_song.mp3 but with different file names, the payload hash and file size should match and they can both just point to the same encrypted file even though their accounts have nothing to do with each other. Would that work in practice? Would it be bad for security even if its done post encryption?

My gut tells me there's a huge percentage of redundant 'public' data in cloud storage services. Maybe they've figured a better way to optimize the storage of redundant data across different user accounts.

Even better, you deduplicate at the block level of the file system by hashing the contents of individual blocks.

And yes, this is something that is done and is explicitly a part of file systems like ZFS.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If you're using one encryption key for everybody then it doesn't really count as "encrypted" from the user's perspective, since the storage provider can just look up the key and use it to decrypt the data.

If each user has their own keys (which the service doesn't know), then those encrypted blocks won't match.

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Oh yeah, I totally glossed over the part where most providers only do de-duplication on the users own data.

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