9
votes
Fortnightly Programming Q&A Thread
General Programming Q&A thread! Ask any questions about programming, answer the questions of other users, or post suggestions for future threads.
Don't forget to format your code using the triple backticks or tildes:
Here is my schema:
```sql
CREATE TABLE article_to_warehouse (
article_id INTEGER
, warehouse_id INTEGER
)
;
```
How do I add a `UNIQUE` constraint?
As someone who was in a similar position not too long ago, I can offer some of my own perspective and advice.
Make sure you maintain industry best practices. This is both for the benefit of the organisation and also for yourself. As a sole operator it is really easy to take the shortest route to completion and develop on-the-fly.
Use git [or some form of vcs], have a sane development, test and deployment pipeline. Given your resources, you can only do so much. Not saying you need to have a huge CI system with every bell and whistle, but have some procedure in place which states how things are done.
Make sure your work passes the 'bus test'. If you were hit by a bus tonight, how would things be able to continue? As I said this isn't just for the organisation but also to make sure you keep yourself skilled and up to date. Things move fast in the software world, today's popular framework or paradigm is quickly replaced by something new. It's easy to get comfortable if a job is simple and you're on your own, but there's a reason these positions earn the title of being 'golden handcuffs'.
I guess where I'm going with it all is that, make sure that if or when you need to move to another job, you are in a good position to do so. I moved from a small near-one-person-show to a large department, primarily as I still had good knowledge and experience.
Honestly, if you don't have the managers and team members around you, just make the most of it! Focus on the technology and find the best ones to suit your needs.
Just make sure that your superiors actually understand what you do for when future potential employers call them up.
While a custom CMS sounds like it should be a positive on a resume, it actually doesn't help much. Lots of hiring is based on your familiarity with common frameworks, so if you can integrate with some of the bigger ones it would be better for your career.
I'm basically in the same shoes as you right now, and a while back I tried my luck on the jobs market and was surprised at how little traction I got. That's a small part of why I decided to go back to school. The class I am taking right now has made me realize that the job that better describes what we do is actually that of an Analyst, so I'm making that my title. But I'm happier with my current job than I was in the past, so I won't know how effective it will be until much later.
Firstly, no managers and no colleagues? You lucky bastard!
Seconldy, what kind of advice are you looking for exactly? It's not quite obvious from your post.
A question regarding HTML and CSS. I've noticed that while the
height
of<html>
depends on the content, itswidth
is always 100 % of the viewport, unless the content stretches that. Is that the standard width (that is, it is written in the standard) or is it an implementation-dependent detail? In other words, can I always count on the width being 100 % without puttingwidth: 100%
into my stylesheets explicitly?My understanding is that
width:100%;
means "100% of the width of the closest relative-positioned block parent element, or root element". If you want to guarantee an element is the width of the viewport,width:100vw;
is what you want.AFAIK width generally defaults to 'auto', which isn't really the same as '100%'.
Thank you for the links! I did some more digging and found this note on MDN:
Which, combined with this quote from the CSS standard:
Pretty much says that the width of
<html>
“has dimensions of the viewport”.(I feel a bit uncomfortable being the only person who asks anything at all, but still…)
An
ed
question: How do I replace all occurrences of a piece text between two patterns? This replaces one occurrence:Is there a way to make this command “global”?
I am not sure about
ed
, but invim
you would add ag
flag to the end of the command. That may be worth a try. So your command would change to:As a side question, why
ed
instead ofvim
or any of its gui adaptations?Isn't the command
%s/searchpattern/replacement/g
to search replace in vim for an entire file? Maybe I missremember...Yes I think that is right. I suppose in this case in vim you would use visual mode to select only the areas that needed search and replace.
Yeah, I know about that in
vim
, but ined
g
is a command of the formg/RE/p
(coincidentally, this is where the name “grep” comes from), so it takes a regexp instead of a couple of addresses, and “flags” aren't really a thing. I've read the entire POSIX standard description ofed
and the GNUed
manual, but I couldn't find anything.ex
actually can dog/BEGIN/,/END/c
, so if everything else fails, I can always use that. I didn't want to useex
, because on most systems it's aliased tovim
and so it is more heavy-weight and not really a command of its own.Several reasons in no particular order:
ed
is the standard text editor.ken
used ed until he androb
createdsam
, so it's an important part of Unix history.sed -i
is a non-POSIX extension, so there are basically only two ways to edit files from the command line in POSIX:ed
andex
, unless there is a hidden editor I am not aware of. And I've already written why I prefered
toex
.Any way, thanks for responding. I guess it goes into the “not quite possible” pile.
The article and overall site you shared here are pretty neat! Reading a bit more about
ed
was nice. I am curious why you would like to use patterns to define your search space rather than line numbers, if that is something you wouldn't mind sharing.I don't! I am quite active on the Russian StackOverflow. One user over there has recentrly asked a question about how one might replace all text between two strings in several texts from the command line. I think they wanted to replace some copy-pasted HTML with a PHP
include
directive. One thing led to another and here I am :-)In general you don't know the exact line numbers when bulk-editing multiple files, so patterns feel like an obvious extension. I kind of wish there was a version of
ed
withsam
's structured regular expressions.I have a git question! Assuming I am on the branch
foo
, origin'sfoo
(upstream) is1234
, and I need to force-push, is this:In any way more safe than this:
The former having
-with-lease
helps some and it further "protects" more than a naked--force-with-lease
(which I normally use) against you (or some program) runninggit fetch
without you realizing after someone else had pushed toorigin/foo
but before you can confirmed you're okay with the force push.I was talking to @ThatFanficGuy about a header for my website, which I have posted here. I have finally gotten it to respond somewhat gracefully to the window changing width, but something I have done is making my content render under my header. My logo is an SVG so I haven't uploaded it anywhere yet, and all the HTML and CSS is from the final output of my static site generator, Jekyll.
Does anyone have any idea why the content is doing this? Also, any general feedback? This is the first time I have tried web development.
position: absolute
Long story short: all content in HTML relies on something called the box model. It's why
display: block
elements –<h1>
,<div>
,<header>
– take up all the width available and push the following content "down".When you position an element absolutely, not only do you make it stick to a set of coordinates within the page, you also take it out of the box model. This means that content will no longer pay attention to it when it comes to considering their own place on the page. In other words, what used to be a large block that takes up space, is no longer a block taking up space, as far as the rest of your content is concerned.
If you do want your content to consider the large block, don't make the block use
position: absolute
.What was it that you meant to achieve using absolute positioning? There are different recommendations to what you want to achieve, and I think I know what you wanted to do. Since you're still learning, I'd like you to verbalize your goals on your own, because that's how you come to understand the problem you're trying to solve via web design. The more you talk through the stuff you're working with, the quicker you'll understand it.
I think I did that because I have having trouble with the green area not aligning with the very top of the browser, which in turn was caused by an element within the green
div
being in the wrong position or maybe the wrong size or margins, pushing the whole thing down. I am not sure though, I spent a lot of time tinkering! Removing the absolute positioning does seem to have solved that quirk, so I will definitely keep in mind that the absolute positioning breaks things completely out of the box model.Keep in mind, for future reference, that there are plenty of reasons to use absolute positioning. Notifications are just one example.
What might be an issue is that browsers set
margin
ofbody
to a certain value (I believe it's 8px in Chrome), which pushes everything inwards, not letting it touch the boundries of the viewport (the part of the page that's in the view – as in, the visual container for all the elements that you can see while scrolling). Good intentions, but often leads to screwy interfaces.My go-to rule is to remove
margin
frombody
by setting it to 0. If I need the elements to not touch the viewport borders, I addpadding: 2.5%
. Doesn't do much on desktop and tablet screens, but helps maintain a reasonable boundry on smaller mobile screens.Oh, and also: there is an element called
<header>
in HTML already. You might want to use it instead of applying classes to<div>
s everywhere, which isn't a good practice. HTML5 added a bunch of cool semantic elements that you might want to familiarize yourself with.I'll be sure to test out on Chrome and see if things are working properly, and I will definitely check out the
<header>
element. It was covered in some overviews of HTML I was looking at before I got started, but I forgot about it while I was tinkering!No worries. I open DevDocs.io as a default action whenever I do web. Everyone searches for minor things all the time in this field.
One of the things I've learned over the years of
workingfighting with CSS is that one is absolutely unable to do the classical header-content-footer trio right without CSS Flexbox or CSS Grid. You can see an example of how I do it with Flexbox on my personal website. The CSS is inline and mostly well-documented. The basic gist of it is:Demo: https:// codepen.io/Ainar-G/pen/abbBGPj.
Hopefully, this helps.
I think I've got it the way I want it by removing the absolute positioning on the top bar. I will keep in mind flexbox and grid. Grid looks especially useful because I have been thinking of making some posts that have code and commentary sort of side by side, though I have no idea how to make that display well on mobile yet.