Programming Thread

General off-topic stuffs goes here.
User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » March 21st, 2016, 4:33 pm

Oh god, that guy. Yeah, he doesn't really seem right in the head. Which is unfortunate because it takes some real skill to make your own operating system even if it's like an early '90s os.
💙💙💙
Image
Image

User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » March 21st, 2016, 8:51 pm

I don't think the early 90's, hell, the history of computing ever put anything out nearly as ugly nor close to being the UI/UX nightmare of TempleOS.

But you're right that he does seem to be a very smart programmer.
Image
► Show Spoiler

User avatar
Tovarisch Red Yoshi
Resident Commie Chameleon
Posts: 1934
Joined: December 29th, 2014, 10:57 pm
Location: Ashtree

Re: Programming Thread

Postby Tovarisch Red Yoshi » March 22nd, 2016, 2:52 am

he's brilliant

and schizo as fuck

he's kinda a lolcow, rare smart ones

he probably doesn't like his ui either, its just god/his literal schizophrenia told him to make it that way

also join the skype group, let insane show you wherehow
wikipedia wrote:The word "w00t" itself was first seen in 1994.[citation needed] The expression rose in popularity in the late 1990s and early 2000s (decade) mostly on MMORPG such as RuneScape. It remains a niche Internet term and is not in general usage. The symbolic approximation of Latin letter forms makes w00t a prime example of internet leetspeak. It may also sometimes be seen spelled as "wewt" or "wought".
Isocitration wrote:<Isocitration> a long obscure nonsequitur that must be explained
<Isocitration> the joke is funny because of that alone
<tovakj> you've known me how long, yet?
<tovakj> yes
<tovakj> you're finally figuring out my aesthetic

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » March 22nd, 2016, 3:53 am

Ashan wrote:I don't think the early 90's, hell, the history of computing ever put anything out nearly as ugly nor close to being the UI/UX nightmare of TempleOS.

But you're right that he does seem to be a very smart programmer.

Actually Windows 1.0 was pretty awful. It was far worse than 3.1 was, that's for sure.
Image
That said though, TempleOS is definitely an enormous mess ui-wise.
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » March 22nd, 2016, 12:38 pm

You know what's both a great feeling and a shit feeling at the same time? The great part is realizing you know how to fix a problem you've been struggling to fix for awhile. The shit part is realizing the solution was actually really freaking obvious in hindsight. My userscript's magnifier function actually has a bit of an issue when the site itself is scaling images. If the site is scaling images then the way I'm getting the image height actually returns a smaller resolution than it should. But if I make an invisible element that has the image embedded at full size I can make it scale properly no matter what.

Also if I'm really feeling like a challenge I can try and merge that canvas pan/zoom code into it to replace the magnifier with that instead. Then I'd just have it default to the scale set in the userscript's settings but allow the user to pan around and zoom in however far they want. (Though I think the zoom method might work better if I actually replaced the canvas' zoom method with one that resizes the image itself instead, otherwise I think zooming in would be really blocky no matter what.)
💙💙💙
Image
Image


Speedless
Posts: 123
Joined: March 20th, 2015, 12:11 am
Location: At the center of a 4-angle spirangle, which is in the refrigerator next to the nice cheese

Re: Programming Thread

Postby Speedless » March 23rd, 2016, 3:20 am

Just a couple days ago, I found out what happens if you try to write a C++ function that returns a reference to a local variable (which is destroyed when the function ends, making the reference useless--maybe even worse than useless). In short, it's fun times!

(it's not actually fun times at all)

I wrote a function called center() that returned a coordinate vector by reference (computing the vector in question within the center() function, in a local variable), and I wanted to use this difference:

Code: Select all

player.center().y - enemy.center().y

The Visual C++ debugger happily told me that the call to player.center() returned, say, the coordinates (330, 399), while the center() call for the enemy returned (200, -156)...

But the difference player.center().y - enemy.center().y was always 0, regardless of what the coordinates actually were--even though, based only on what the debugger said about the returned values, you would think that the program was trying to compute something like 399 - (-156)!

(What I'm guessing was actually happening is that the same spot in memory gets used for both values--so player.center() and enemy.center() end up pointing to the same object, the one returned by the last call to center(), and naturally the difference between enemy.center().y and itself is 0.)

Just returning the vector by value instead of by reference fixed it. So I guess the moral of the story is "hey, let's be careful out there."

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » March 25th, 2016, 2:14 pm

Alice wrote:You know what's both a great feeling and a shit feeling at the same time? The great part is realizing you know how to fix a problem you've been struggling to fix for awhile. The shit part is realizing the solution was actually really freaking obvious in hindsight. My userscript's magnifier function actually has a bit of an issue when the site itself is scaling images. If the site is scaling images then the way I'm getting the image height actually returns a smaller resolution than it should. But if I make an invisible element that has the image embedded at full size I can make it scale properly no matter what.

Finally got to trying this because I was feeling alright. Got it mostly implemented after a really stupid type that confused the hell out of me

Code: Select all

$(`<div id="thingifier-magnifier-placeholder"><img id="thingifier-magnifier-placeholder-image" src="></div>`).insertAfter("#reader");

Code: Select all

$(`<div id="thingifier-magnifier-placeholder"><img id="thingifier-magnifier-placeholder-image" src=""></div>`).insertAfter("#reader");

There's a one character difference between those. The difference causes the image tag to not get inserted into the page which is confusing as fuck when the div gets inserted.

Anyways after that little debacle I had it working right other than two issues. The first is that the movement of the magnifier doesn't scale properly if the page has been scaled using the site's thumbnail option. It always acts as if the underlying image is the fullsized one which I'm not entirely certain how to fix. The other more major issue however is the fact that, for some reason that I wasn't quite able to figure out before stopping, the background image for the magnifier would start right around the same spot as the placeholder image I was using to get the proper image height and I seemed to barely be able to affect this for some reason. I ended up having to stop about that point though because allergies decided to say hi and I lost all ability to concentrate worth a damn shortly after a sneezing fit.
💙💙💙
Image
Image


User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » March 25th, 2016, 6:24 pm

I contributed to a fairly large open source project for my first time, and this morning the author merged my pull request.

It was pretty minor, only about 40 lines of code, but I think this is the first time that I wrote some code that a decently-sized amount of people will use. It feels good!
Image
► Show Spoiler

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » March 25th, 2016, 7:15 pm

Ashan wrote:I contributed to a fairly large open source project for my first time, and this morning the author merged my pull request.

It was pretty minor, only about 40 lines of code, but I think this is the first time that I wrote some code that a decently-sized amount of people will use. It feels good!

https://medium.com/@Rich_Harris/how-to- ... .6r015irho

Don't underestimate your code just because of its line count. Depending on its context it could turn out to be something important even if it's something pretty simple.
💙💙💙
Image
Image


User avatar
Tovarisch Red Yoshi
Resident Commie Chameleon
Posts: 1934
Joined: December 29th, 2014, 10:57 pm
Location: Ashtree

Re: Programming Thread

Postby Tovarisch Red Yoshi » March 25th, 2016, 8:16 pm

Ashan wrote:I contributed to a fairly large open source project for my first time, and this morning the author merged my pull request.

It was pretty minor, only about 40 lines of code, but I think this is the first time that I wrote some code that a decently-sized amount of people will use. It feels good!


smol usually more efficient, superior

horror story: programmer friend working on project. Cleans a 500 line mess down to 10,20 lines. project overseer docks him pay for only contributing 20 lines of code that day

might have been 5000, 100. I'm sleepy today
wikipedia wrote:The word "w00t" itself was first seen in 1994.[citation needed] The expression rose in popularity in the late 1990s and early 2000s (decade) mostly on MMORPG such as RuneScape. It remains a niche Internet term and is not in general usage. The symbolic approximation of Latin letter forms makes w00t a prime example of internet leetspeak. It may also sometimes be seen spelled as "wewt" or "wought".

Isocitration wrote:<Isocitration> a long obscure nonsequitur that must be explained
<Isocitration> the joke is funny because of that alone
<tovakj> you've known me how long, yet?
<tovakj> yes
<tovakj> you're finally figuring out my aesthetic


User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » March 25th, 2016, 8:52 pm

Hah, yeah I suppose line count doesn't matter. It was a relatively small feature though.

Basically, whenever the app launched, it would start you off on a completely blank, white screen. The first time I opened the app I thought it had some error loading, cause it was just a white screen. It turns out there's no launch screen, you're just supposed to type a search to get started.
So I added in a background to the launch screen telling the user to do something:
http://i.imgur.com/d9eDqea.png
Image
► Show Spoiler

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » March 25th, 2016, 9:41 pm

Ashan wrote:Hah, yeah I suppose line count doesn't matter. It was a relatively small feature though.

Basically, whenever the app launched, it would start you off on a completely blank, white screen. The first time I opened the app I thought it had some error loading, cause it was just a white screen. It turns out there's no launch screen, you're just supposed to type a search to get started.
So I added in a background to the launch screen telling the user to do something:
http://i.imgur.com/d9eDqea.png

Might be a pretty small feature but that sounds like something that'd actually have more of an effect than you might think. Usability is often what puts software above the competition. That's one of the big reasons something like Windows or OSX are more popular than Linux or Photoshop with Gimp. It's not too unusual for the most popular software in a given niche to not even be as flexible or powerful as its competition. It'll often win just because it's not a mess to use even if it's technically inferior otherwise.
💙💙💙
Image
Image


User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » March 25th, 2016, 9:51 pm

Hah, you know I actually just now looked back at a popular Reddit thread about the app:
https://www.reddit.com/r/Android/commen ... al_design/

Apparently I had the highest rated comment, and I was pointing out that exact flaw. I knew I had mentioned it on Reddit before, but I didn't remember it being that popular. So yeah, apparently there's demand for it!
Image
► Show Spoiler

User avatar
Tovarisch Red Yoshi
Resident Commie Chameleon
Posts: 1934
Joined: December 29th, 2014, 10:57 pm
Location: Ashtree

Re: Programming Thread

Postby Tovarisch Red Yoshi » March 29th, 2016, 7:23 am

EDIT:

tl;dr

Any of you know how to use a regexp to turn ā.a.ā.a > ā..ā. where . is any character and it's preserved? Especially in geany

Original

So a conlanging thing...

I have a list of about 5000 words. I need to apply some some sound changes and pay attention to morphological changes. There are tools, but the two I can think of, one is command line, one is java and is having a ton of problems applying my sound laws and I have no idea why. So I'm trying to teach myself regular expressions

Sound laws tend to pretty absolute and simple to simulate. They all take if then forms; sometimes it's easier to write if then unless though.

I'm working with geany, an IDE - closer to notepad than emacs but a lot of nice features. Control H brings up the find and replace menu, which can take regexp

The status constructus form of nouns and participles (a grammar thing) takes the form āCaCāCa where C is any consonant. The short as need to go (so āCaCāCa > āCCāC). I can find them with ā.a.ā.a and I reckon there's a way to define a class of characters eg [ptk]a[rlyw] when I come to it, but

how to you make the replace ignore the characters in the . slot?

I want a rule that's ā.a.ā.a > ā..ā. where the .s are any character, and preserved.
wikipedia wrote:The word "w00t" itself was first seen in 1994.[citation needed] The expression rose in popularity in the late 1990s and early 2000s (decade) mostly on MMORPG such as RuneScape. It remains a niche Internet term and is not in general usage. The symbolic approximation of Latin letter forms makes w00t a prime example of internet leetspeak. It may also sometimes be seen spelled as "wewt" or "wought".

Isocitration wrote:<Isocitration> a long obscure nonsequitur that must be explained
<Isocitration> the joke is funny because of that alone
<tovakj> you've known me how long, yet?
<tovakj> yes
<tovakj> you're finally figuring out my aesthetic


User avatar
chridd
Posts: 204
Joined: December 25th, 2014, 9:20 pm
Location: the internet
Contact:

Re: Programming Thread

Postby chridd » March 29th, 2016, 8:47 am

Tovarisch Red Yoshi wrote:EDIT:

tl;dr

Any of you know how to use a regexp to turn ā.a.ā.a > ā..ā. where . is any character and it's preserved? Especially in geany
The exact syntax depends on the program you're using, but in most regular expression engines:
• If you put parentheses around some text, then it'll remember what matched there so you can use it in the replacement, so ā(.)a(.)ā(.)a. In some programs (especially in old Unix programs like grep and vi), you need a backslash before each parenthesis, like ā\(.\)a\(.\)ā\(.\)a. Whichever of these the program doesn't use will probably be used for finding actual parentheses.
• In the replacement string, in many programs the parenthesized expressions can be referred to as $1, $2, etc., so ā$1$2ā$3. Some programs use backslash instead, so ā\1\2ā\3.

User avatar
Tovarisch Red Yoshi
Resident Commie Chameleon
Posts: 1934
Joined: December 29th, 2014, 10:57 pm
Location: Ashtree

Re: Programming Thread

Postby Tovarisch Red Yoshi » March 29th, 2016, 9:02 am

chridd wrote:
Tovarisch Red Yoshi wrote:EDIT:

tl;dr

Any of you know how to use a regexp to turn ā.a.ā.a > ā..ā. where . is any character and it's preserved? Especially in geany
The exact syntax depends on the program you're using, but in most regular expression engines:
• If you put parentheses around some text, then it'll remember what matched there so you can use it in the replacement, so ā(.)a(.)ā(.)a. In some programs (especially in old Unix programs like grep and vi), you need a backslash before each parenthesis, like ā\(.\)a\(.\)ā\(.\)a. Whichever of these the program doesn't use will probably be used for finding actual parentheses.
• In the replacement string, in many programs the parenthesized expressions can be referred to as $1, $2, etc., so ā$1$2ā$3. Some programs use backslash instead, so ā\1\2ā\3.



Thank you!
wikipedia wrote:The word "w00t" itself was first seen in 1994.[citation needed] The expression rose in popularity in the late 1990s and early 2000s (decade) mostly on MMORPG such as RuneScape. It remains a niche Internet term and is not in general usage. The symbolic approximation of Latin letter forms makes w00t a prime example of internet leetspeak. It may also sometimes be seen spelled as "wewt" or "wought".

Isocitration wrote:<Isocitration> a long obscure nonsequitur that must be explained
<Isocitration> the joke is funny because of that alone
<tovakj> you've known me how long, yet?
<tovakj> yes
<tovakj> you're finally figuring out my aesthetic


User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » March 30th, 2016, 4:24 pm

So have we officially found the year of Linux on desktop?
http://www.theverge.com/2016/3/30/11331 ... buntu-bash
Image
► Show Spoiler

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » March 30th, 2016, 5:03 pm

Ashan wrote:So have we officially found the year of Linux on desktop?
http://www.theverge.com/2016/3/30/11331 ... buntu-bash

I was just reading about that a little while ago. Apparently Microsoft has a habit of embracing stuff like that only to add more and more proprietary stuff to it to try to make users move to Windows for it instead which people are worried about. Though I dunno that Microsoft would bother. They're more interested in your data than crushing the competition anymore.
💙💙💙
Image
Image


User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » March 30th, 2016, 9:01 pm

I'm just happy to have BASH on Windows.
Image
► Show Spoiler

User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » March 30th, 2016, 9:43 pm

Here's a demo:
https://channel9.msdn.com/Events/Build/2016/P488

Seems to have all the bells and whistles. I'm very excited for this. I can finally get rid of that stupid ugly git bash program I have to use every time I want to use git on my Windows machine.
Image
► Show Spoiler

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » April 7th, 2016, 4:11 am

Apparently drawing ANY element on a fullscreen video is basically impossible, at least in Firefox. I'm attempting to replace Magic Actions for Youtube since the devs apparently decided to abandon Firefox development. There's only a few functions I really use all that much from it. Mousewheel volume controls, prevent videos from autoplaying, and set resolution automatically. Stopping autoplay was pretty easy once I figured it out. Mousewheel volume controls isn't too difficult either actually. There's one issue but it's not something Magic Actions actually supported either. You can't draw an element above a fullscreen video. I've found some info on it and it's because videos in fullscreen use "z-index: 2147483647;" and you physically cannot change that number apparently. And this is the maximum number that the z-index rule supports so you can't draw anything above it. I keep seeing stuff about setting your element's z-index to be the same and it appearing above the video like I'm wanting but it just does not work that way.

https://jsfiddle.net/Alice3173/pa9L4jmj/4/

Code: Select all

*:fullscreen, *:-moz-full-screen {
  z-index: 2147483646 !important;
}
#overlay, #overlay:fullscreen, #overlay:-moz-full-screen {
  width: 64px;
  height: 32px;
  border: 1px solid teal;
  background-color: aliceblue;
  text-align: center;
  position: fixed;
  left: calc(50vw - 32px);
  top: 16px;
  z-index: 2147483647 !important;
  opacity: 0;
}

As you can see here I tried just setting the z-index of everything to the lower number as well as setting my overlay's z-index to the max. (And covering my bases by using the base fullscreen prefix as well as the Mozzarella specific one.) It'd be nice to find a way to deal with this but I'm having trouble even finding information on the defaults of the :fullscreen parameter in the first place.

Then past that I just need to figure out how I should set the resolution of a Youtube video by default then actually move my code over to a userscript so I can test that it all works properly on Youtube. I'd really like to figure out this fullscreen crap before doing all that though.
💙💙💙
Image
Image


User avatar
chridd
Posts: 204
Joined: December 25th, 2014, 9:20 pm
Location: the internet
Contact:

Re: Programming Thread

Postby chridd » April 7th, 2016, 5:01 pm

Alice wrote:

Code: Select all

*:fullscreen, *:-moz-full-screen {
Combining prefixed and non-prefixed selectors doesn't work. If a browser doesn't understand a selector, then it ignores the entire rule, so this will only work on browsers that understand both :fullscreen and :-moz-full-screen. To support browsers that only support one or the other, you have to duplicate the entire rule, like:

Code: Select all

*:fullscreen {
  z-index: 2147483646 !important;
}
*:-moz-full-screen {
  z-index: 2147483646 !important;
}
(Yes, it's annoying.)

Second, it must be possible to put an element in front of a full-screen video, because the controls are such an element. You probably need to make the element be in the right place in the HTML (I think it would need to be inside the #movie_player element). This assumes you're using the HTML5 player; I doubt you can put things in front of full screen video with the Flash player.

User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » April 7th, 2016, 7:55 pm

Apparently the latest Windows 10 preview has Bash and whatnot. I tried upgrading to the preview but Windows updater is the most unreliable piece of shit software on the planet so even though I joined the insider program a day ago, I still haven't gotten the update.
Image
► Show Spoiler

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » April 8th, 2016, 12:12 am

chridd wrote:[Combining prefixed and non-prefixed selectors doesn't work. If a browser doesn't understand a selector, then it ignores the entire rule, so this will only work on browsers that understand both :fullscreen and :-moz-full-screen. To support browsers that only support one or the other, you have to duplicate the entire rule, like:

Code: Select all

*:fullscreen {
  z-index: 2147483646 !important;
}
*:-moz-full-screen {
  z-index: 2147483646 !important;
}
(Yes, it's annoying.)

What the hell. I never knew that. What a strange quirk.
Second, it must be possible to put an element in front of a full-screen video, because the controls are such an element. You probably need to make the element be in the right place in the HTML (I think it would need to be inside the #movie_player element). This assumes you're using the HTML5 player; I doubt you can put things in front of full screen video with the Flash player.

The controls appear like that because the default CSS (the stuff that's apparently supposed to be unmodifiable) puts it there. In fact from what I've read the only way to even get rid of fullscreen html5 controls is simply to move them off-screen so your own can replace them. You might have a point on the location of my overlay though.

Edit: I just gave that a try and now it doesn't even appear in front of the video non-fullscreen. And this despite the video being set to a z-index of 0 with the overlay being set to the max.

Code: Select all

video {
  width: 90vw;
  margin-left: 5vw;
  margin-right: 5vw;
  z-index: 0 !important;
}
*:fullscreen {
  z-index: 2147483646 !important;
}
*:-moz-full-screen {
  z-index: 2147483646 !important;
}
#overlay:fullscreen {
  z-index: 2147483646 !important;
}
#overlay:-moz-full-screen {
  z-index: 2147483646 !important;
}
#overlay {
  width: 64px;
  height: 32px;
  border: 1px solid teal;
  background-color: aliceblue;
  text-align: center;
  position: fixed;
  left: calc(50vw - 32px);
  top: 16px;
  z-index: 2147483647 !important;
  opacity: 0;
}
💙💙💙
Image
Image


User avatar
chridd
Posts: 204
Joined: December 25th, 2014, 9:20 pm
Location: the internet
Contact:

Re: Programming Thread

Postby chridd » April 8th, 2016, 1:13 am

Are you right-clicking the video and choosing "Full screen"? Because that's not how YouTube does full-screen. (If you shift-right-click a YouTube video and choose Full screen, then none of the controls show up. If you enter full-screen normally, they do.)

Try this (or try making an actual userscript rather than a jsfiddle)
(Also jsfiddle doesn't seem to allow full-screen. Also the video on my example page doesn't actually fill the screen in fullscreen mode, but it probably won't have that problem on YouTube. Fixed)

When a page enters full screen, it sets a specific element on that page to full screen; things inside that element will be visible, everything else won't be. If you use the full screen option on a video context menu (provided by the browser), then it makes the video fullscreen, so you can't see anything else. If you make an element containing the video full screen (from JavaScript), then everything in that element will be visible.

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » April 8th, 2016, 1:28 am

chridd wrote:Are you right-clicking the video and choosing "Full screen"? Because that's not how YouTube does full-screen. (If you shift-right-click a YouTube video and choose Full screen, then none of the controls show up. If you enter full-screen normally, they do.)

Try this (or try making an actual userscript rather than a jsfiddle)
(Also jsfiddle doesn't seem to allow full-screen. Also the video on my example page doesn't actually fill the screen in fullscreen mode, but it probably won't have that problem on YouTube. Fixed)

When a page enters full screen, it sets a specific element on that page to full screen; things inside that element will be visible, everything else won't be. If you use the full screen option on a video context menu (provided by the browser), then it makes the video fullscreen, so you can't see anything else. If you make an element containing the video full screen (from JavaScript), then everything in that element will be visible.

Yeah, that's what I was doing. And I was testing it on JSFiddle rather than Youtube. I haven't done a lot on the Youtube side of things, partly because for some random reason Firefox's dev tools will freeze Firefox but only on Youtube. (And I've been having issues even getting Firefox to start lately for some reason, I think I need to stop being lazy and reinstall Windows even though it's an enormous pain in the ass and time sink.)

I do see what you mean though. The overlay appears in fullscreen on your site when I use the fullscreen button but not if I right click and choose fullscreen. I'm not entirely sure how Youtube handles it either yet.
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » May 6th, 2016, 5:29 pm

https://jsfiddle.net/Alice3173/z19503ns/2/


I probably handled the characters the worst way possible because my allergies are acting up way too bad for me to concentrate enough to figure out why I was getting a "malformed unicode escape character" error when trying to generate characters totally at random (I was generating a string of "\u" plus a four digit hex code at the end for each character) but since Nexus Mods got compromised (again...) and my Amazon account randomly started rejecting the password (totally randomly since it wasn't changed...) I did that to make generating random passwords easier rather than just coming up with passwords.

You can set the password's length as well as disable unicode characters though. If I were to redo it I'd try to make it a little more usable with an actual UI on the page instead of editing code, as well as checkboxes for including or excluding certain kinds of characters, and trying to get it to work closer to how I was originally doing it so I wouldn't need to have huge arrays of characters for each option.
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » May 17th, 2016, 12:57 am

https://jsfiddle.net/Alice3173/28xn63Lk/3/


After watching this video I decided to try my hand at making an rng myself. It could probably be a lot better, especially since I have a bit of trouble wrapping my head around the bitwise operators, but I think that turned out reasonably well. Seems to average around 60,000 values before it encounters a value it already previously generated at which point I believe it'd be stuck in a loop. Edit: Actually after updating it to keep track of average values generated it looks to be closer to 72,000, neat.

Edit2: It's less efficient now but I managed to find a way to get it to the ~210,000 loops before finding a duplicate range. Though after being confused about how to get it to work but be more efficient I realized that's not even an issue anyways. That's over 200,000 loops in like a quarter of a second when an rng, even in a game, isn't going to be called more than like a few thousand times a frame at the very most. Though I am confused. Apparently bitwise operations don't follow the order of operations or something so I'm unsure what the difference between these is:

This is the code I'm currently using:

Code: Select all

var r1 = ~input,
   r2 = input ^ 1,
   r3 = input << 8,
   r4 = input ^ (r2 ^ r3),
   rx = r1 + r2 + r3 + r4 + input;
input = rx >>> 5;

This code:

Code: Select all

var r1 = ~input,
   r2 = input ^ 1,
   r3 = input << 8,
   r4 = r2 ^ r3,
   r5 = input ^ r4,
   rx = r1 + r2 + r3 + r4 + r5 + input;
input = rx >>> 5;

should have the same exact result as the first code but it doesn't. It runs through FAR fewer loops before hitting a duplicate. Edit: Nevermind. I just realized I actually messed up in that second version. There should be no "+ r4" in the rx bit since I was just splitting the original r4 into two steps there.
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » May 17th, 2016, 9:15 am

https://jsfiddle.net/Alice3173/47zz0d7c/4/

Still uses the same underlying rng algorithm I made up because compared to everything else I've tried this one works the best but I think this is about as good as I can get it as of now. The rng is reseeded on average about every 520th iteration or so. And to break out of loops that still happen (one does when the seed hits 55330 currently) I have a fallback check which will forcefully reseed it if it goes long enough without reseeding.

Also odd note about the way I'm handling the rng algorithm: Literally every other method I've tried using those same numbers is somehow less efficient. Using javascript's performance.now() function to get sub-millisecond precision basically any change I made to the way I'm handling things increased iteration times by at least 15-20%. This include removing the rx variable and inputting its value straight into the return as well as r1. r2/3/4 though are actually more efficient this way if I'm understanding things correctly since it's not redoing some extra math. Really not certain why everything else is more efficient this way however.
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » May 18th, 2016, 10:07 am

Image
This is an image of values generated by my rng. It's 1000000 iterations (starting from a seed of 1) with the opacity of a given pixel being dictated by the rng value associated with said pixel divided by the highest number recorded during my iteration process.

https://jsfiddle.net/1anLpqrz/4/
The algorithm itself is a bit different than it was before. The previous one had some pretty obvious patterns in it so I tweaked it a bunch until I finally found the pattern shown here which seems to be significantly more random, albeit still not perfect by any means. This is the new algorithm by the way:

Code: Select all

var r1 = ~input,
    r2 = input ^ 128,
    r3 = input << 8,
    r4 = input ^ (r2 ^ r3),
    rx = r1+ r2 + r3 + r4 + input;
input = rx >>> r3;
if ((rng.iterations - rng.lastupdate) > rng.reseed_value && rng.auto_reseed) {
    rng.seed = rng.reseed(rng.seed);
}
if (input % 100 === 0) {
    var rmod = ((rng.reseed_value << 3) ^ r3) >>> 1;
    input = (input ^ rmod) + (rmod ^ 37);
}

As you can see, in addition to the changes to the algorithm itself I made it a bit more self-sustaining. It'll now reseed itself when it's gone X iterations and it will do a bit of a jump in values if the current input value ends in 00.
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » May 23rd, 2016, 8:45 am

I just found out that javascript's JSON.stringify() command has some optional stuff for formatting that's REALLY useful.

Code: Select all

JSON.stringify(object, null, 4)

or

Code: Select all

JSON.stringify(object, null, "    ")

This will return a formatted version of the object with proper indentation unlike if you just use JSON.stringify. The null bit has something to do with running functions on the output or otherwise dictating how the output gets handled or something. I didn't quite understand it though.

Super useful though to declare a new function to utilize that easier though. Something like this would work:

Code: Select all

function stringify(text) {
     return JSON.stringify(text, null, 4);
}


Kinda simple but it's not something I'd known about before now.



Also on that note: Messing with textareas is a pain in the ass. Through basic javascript or jQuery doing something like inserting a newline into the textarea doesn't like to work if you're intercepting enter for something else. Inserting <br> at the cursor doesn't work, inserting \n doesn't either, inserting &#13;&#10; doesn't either. In the end the only thing I came across that would actually work was inserting \u000A. (The page I got that from suggested \u000A\u000D but that results in two newlines for me.)
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » September 22nd, 2016, 9:27 pm

I decided for the hell of it to try and make my own versions of Javascript's ceil, floor, and round functions.

(Note: It'll take several seconds to load because it's running each function a billion times.) https://jsfiddle.net/Alice3173/k9uLL8mt/3/

I wasn't expecting to actually get better performance and I realized after the fact it only works properly for positive numbers (negatives are always one off from where they should be) but this turned out to work better than I was expecting. Also a really interesting thing to note is that my floor function runs slower at lower iterations but quicker at higher iterations. Though the fact that a billion iterations only takes a max of 1.2 seconds for even my worst performing function is pretty interesting.

The functions themselves if people don't want to take the time to let it load:

Code: Select all

function floor(num) {
   return num - (num % 1);
   //return num << 0;
}

function ceil(num) {
   return (num % 1) ? (num << 0) + 1 : num;
   /*if (num % 1 !== 0) {
      num = (num << 0) + 1;
   }
   return num;*/
}

function round(num) {
   return !!((num % 1) + 0.5 >> 0) ? num + 1 >> 0 : num >> 0;
   /*if (num % 1 >= 0.5) {
      return num = (num << 0) + 1;
   } else {
      return num << 0;
   }*/
}

The commented out methods being my previous ones. In the cases of ceil and floor the other methods provide little to no difference in performance but give the same result. The difference between the two different round methods gives about a 0.3s/1000000000 iterations performance difference. Also it's surprisingly difficult to find examples of how these functions tend to be implemented in different languages. Either that or I just have no idea what terms to search in order to find useful information on the subject.
💙💙💙
Image
Image


User avatar
chridd
Posts: 204
Joined: December 25th, 2014, 9:20 pm
Location: the internet
Contact:

Re: Programming Thread

Postby chridd » September 23rd, 2016, 2:27 am

Alice wrote:Also it's surprisingly difficult to find examples of how these functions tend to be implemented in different languages. Either that or I just have no idea what terms to search in order to find useful information on the subject.
In hardware (e.g., the function used by C on most Linux systems on x86 just uses the "roundsd" assembly instruction), or using bit manipulation. (Found through http://stackoverflow.com/questions/6208488/implementation-of-ceil-and-floor, which was one of the first results for gnulibc source floor.) Languages that don't have those capabilities (e.g., JavaScript) likely have standard floating point functions written in C or something similar.

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » September 23rd, 2016, 4:03 am

chridd wrote:In hardware (e.g., the function used by C on most Linux systems on x86 just uses the "roundsd" assembly instruction), or using bit manipulation. (Found through http://stackoverflow.com/questions/6208488/implementation-of-ceil-and-floor, which was one of the first results for gnulibc source floor.) Languages that don't have those capabilities (e.g., JavaScript) likely have standard floating point functions written in C or something similar.

Thanks, that's actually pretty interesting. And from what I know, Javascript tends to be coded in C++ (in Firefox at least, as far as I'm aware) so it probably uses the C++ implementation in order to keep the function optimized. I have no idea if there's a place you could see a browser's implementation of it though to be sure, nor where you'd find it if there is a public place you can view it.

Fake-edit cause I had an idea to try and find it: I did find this which looks like it may be it. (Found that from this page then blindly stumbling my way through the different links there until I found my way to the Firefox release stream's codebase.)

Code: Select all

js::math_ceil_impl(double x)
{
    return fdlibm::ceil(x);
}

From what I've been able to find out, since the main site for FDLIBM doesn't seem to explain very well what it's supposed to be, is that it's making use of a C++ version of a C math library. At least that's my guess since it's clearly a C++ file. Though I recall reading that most C code is compatible with C++ so it may just be flat out using the C library. Actually now that I look closer, the FDLIBM ceil() function is linked on the Stack Overflow page you linked even, lol. So this implementation should be this which comes out to this if you don't want to have to download the file:

Code: Select all

/* @(#)s_ceil.c 1.3 95/01/18 */
/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * ceil(x)
 * Return x rounded toward -inf to integral value
 * Method:
 *   Bit twiddling.
 * Exception:
 *   Inexact flag raised if x not equal to ceil(x).
 */

#include "fdlibm.h"

#ifdef __STDC__
static const double huge = 1.0e300;
#else
static double huge = 1.0e300;
#endif

#ifdef __STDC__
   double ceil(double x)
#else
   double ceil(x)
   double x;
#endif
{
   int i0,i1,j0;
   unsigned i,j;
   i0 =  __HI(x);
   i1 =  __LO(x);
   j0 = ((i0>>20)&0x7ff)-0x3ff;
   if(j0<20) {
       if(j0<0) {    /* raise inexact if x != 0 */
      if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
          if(i0<0) {i0=0x80000000;i1=0;}
          else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
      }
       } else {
      i = (0x000fffff)>>j0;
      if(((i0&i)|i1)==0) return x; /* x is integral */
      if(huge+x>0.0) {   /* raise inexact flag */
          if(i0>0) i0 += (0x00100000)>>j0;
          i0 &= (~i); i1=0;
      }
       }
   } else if (j0>51) {
       if(j0==0x400) return x+x;   /* inf or NaN */
       else return x;      /* x is integral */
   } else {
       i = ((unsigned)(0xffffffff))>>(j0-20);
       if((i1&i)==0) return x;   /* x is integral */
       if(huge+x>0.0) {       /* raise inexact flag */
      if(i0>0) {
          if(j0==20) i0+=1;
          else {
         j = i1 + (1<<(52-j0));
         if(j<i1) i0+=1;   /* got a carry */
         i1 = j;
          }
      }
      i1 &= (~i);
       }
   }
   __HI(x) = i0;
   __LO(x) = i1;
   return x;
}
💙💙💙
Image
Image


User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » October 15th, 2016, 1:24 am

https://jsfiddle.net/Alice3173/kmpt97xx/5/

I decided to try my hand at escaping characters for no real reason. Had a bunch of trouble actually getting it to cooperate because of a hilarious oversight on my part.

Code: Select all

function escaper(input) {
     "use strict";
   var output = [];
   for (var i = 0; i < input.length; i++) {
      var code = input.charCodeAt(i);
      for (var j = 0; j < escapes.length; j++) {
         var dbg = input.charAt(i).match(escapes[j].char);
         if (typeof dbg === "object" && dbg !== null) {
            var escape = pad(code.toString(), "0", 4);
            output[i] = `&#${escape};`;
            j = escapes.length;
         } else {
            output[i] = input.charAt(i);
         }
      }
   }
   output = output.join("");
   return output;
}

The "j = escapes.length;" line used to not be there and it would cause the loop to keep continuing and unless the character it just escaped happened to be on the final loop anyways it would end up running that else statement thus unescaping it. Also that if check was an enormous pain in the ass to get to cooperate. It kept erroring out and reporting that dbg was null until I erased the check and rewrote it. Still not certain why it errored out to begin with. The "escapes" array could also be edited down quite a lot. It doesn't need each entry to be in its own object and the names and replacement entries are also no longer necessary. It can also be extended to escape any other characters you want simply by adding a new entry with the necessary regex. (Ie: This would be the necessary code to escape an "A" with the current array structure:

Code: Select all

{
    char: /[A]/g
}
)

Edit:
https://jsfiddle.net/Alice3173/kmpt97xx/6/
Decided to go ahead and restructure the array to not have so much unnecessary crap even though I don't have any intentions nor plans on making use of this, lol.
💙💙💙
Image
Image


User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » October 15th, 2016, 2:53 am

I haven't posted here in a while.

In my operating systems class we've been learning about how to make direct system calls which is pretty cool. We've done stuff like make a program that copies a file into a new file (similar to the cp command in Linux), and yesterday we learned how to do process forking and exec* commands which was pretty neat.
(ignore broken indentation. It was written in emacs and this screenshot was taken in Sublime Text)
Image
Image
► Show Spoiler

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » October 15th, 2016, 4:27 am

Ashan wrote:I haven't posted here in a while.

Should post here more often. Zero's never even around anymore and chridd doesn't often post here either (plus sometimes I'll go months without really doing any programming of any sort myself) so it's a tad dead far too often.

Also question because I have very little experience with C++. I know that *var is a pointer and I forget what it is for certain but &var is something similar but what's that **var you're using? That's not one I've seen before.
💙💙💙
Image
Image


User avatar
Ashan
Posts: 485
Joined: February 15th, 2015, 1:33 am
Location: Saskatchewan
Contact:

Re: Programming Thread

Postby Ashan » October 15th, 2016, 5:00 am

Alice wrote:Also question because I have very little experience with C++. I know that *var is a pointer and I forget what it is for certain but &var is something similar but what's that **var you're using? That's not one I've seen before.

It's actually pretty much exactly what you'd deduce from what you said. *var is pointer, &var is the address of the variable, and **var is a pointer to a pointer. I'm actually not super great with my understanding of them, so take my explanation with a grain of salt, but this is how it works in my head:
A pointer to a char can be used similar to a string. The pointer is pointing to the address of the first char in memory, and then subsequent memory addresses store other chars. So if that's a regular pointer to a char, then making a pointer to a pointer is making it so each address pointed to is storing 1 char pointer. It's kinda hard to explain, and it's even kind tough for me to conceptualize but hopefully that makes sense. Similar to a 2-dimensional array, but with dynamic memory allocation.
Image
► Show Spoiler

User avatar
Alice
⦂☽
Posts: 3722
Joined: December 23rd, 2014, 10:47 pm
Location: Wonderland
Contact:

Re: Programming Thread

Postby Alice » October 15th, 2016, 5:29 am

Oh jeez, lol. That sounds confusing. I have trouble wrapping my head around pointers to begin with to be honest. Like I get the idea but I struggle to understand how/why they'd actually be useful if that makes sense.
💙💙💙
Image
Image


Speedless
Posts: 123
Joined: March 20th, 2015, 12:11 am
Location: At the center of a 4-angle spirangle, which is in the refrigerator next to the nice cheese

Re: Programming Thread

Postby Speedless » October 15th, 2016, 6:03 pm

Alice wrote:Oh jeez, lol. That sounds confusing. I have trouble wrapping my head around pointers to begin with to be honest. Like I get the idea but I struggle to understand how/why they'd actually be useful if that makes sense.

Yeah, pointers can be a lot of trouble unless you're exceptionally careful (that is, even more careful than you have to be just in general when you're programming)--especially when you're using them to allocate memory on the heap with new/delete. I'm pretty sure Bjarne Stroustrup himself recommends using alternatives (like an STL container instead of an int* when what you need is a variable-size array) when it's practical to do so.

The impression I got about pointers is that they're the way things were done in C. That is, they were "useful" because they were the only way you could even do certain kinds of memory management. Now, I've been doing applications programming, not operating systems or anything, but I haven't used new/delete in a good while, and I haven't missed them much (thanks to STL containers, std::string, etc.). So in one sense, maybe they're not all that useful... when you have access to the standard library for the project you're doing, at least.

As far as the char**, like Ashan said, it's a pointer to a pointer. Since a "C-style string" (the datatype they use for strings in all the old string functions like strlen, strncpy, etc.) is just a char*, a double-pointer (char**) is one way to get a variable-sized array of strings.


Return to “General Perversion”

Who is online

Users browsing this forum: No registered users and 1 guest