A tab is not made out of spaces. It is a tab, whether in Java, Python, Rust, or generic text file editing. It is represented by a single Unicode character, U+0009.
It does not generally mean “insert this many spaces here” either. It means “put the cursor at the next closest tab stop in the line”. What that means exactly depends on the context. On an old typewriter I had, a tab key would advance the roller to the next column that was a multiple of 10
That is pretty much the same function as the tab character does.
Just for reference, modern text editors have their tab stops set to either every 4 or every 8 characters. That doesn’t mean that 1 tab = 4/8 spaces, that means that putting in a tab will align the cursor with the next multiple of 4/8 columns
In mainstream IDEs you can set the tab key to insert a desired number of spaces instead of a tab character.
The concept of tab independent of space is rarely used these days. In any case, what the character represents is decoupled from what the key does is decoupled from what the screen shows.
In many IDEs, the tab character inserts the required number of spaces to advance to the next tab line. This is often a default.
I imagine it’s a compromise between tab loving extremists and space advocates. The ideal whitespace character is a subject of intense debate among programmers.
Constructive criticism accepted: Dropping this code in case someone is interested in an automated ordering script for their business. Please read the license agreement and Readme file. 🫡 submitted by /u/Hav0cPix3l [link] [comments]
Handling HTTP errors globally can save you time and ensure that your app gracefully handles unexpected situations. You can achieve this in…Continue reading on The 60-Second Programmer »
Hello fellow programs! tl;dr some revisions to the rules to reduce low quality blogspam. The most notable are: banning listicles ("7 cool things I copy-pasted from somebody else!"), extreme beginner articles ("how to use a for loop"), and some limitations on career posts (they must be related to programming careers). Lastly, I want feedback on these changes and the subreddit in general and invite you to vote and use the report button when you see posts that violate the rules because they'll help us get to it faster. r/programming's mission is to be the place with the highest quality programming content, where I can go to read something interesting and learn something new every day. Last time we spoke I introduced the rules that we've been moderating by to accomplish that. Subjectively, quality on the subreddit while not perfect is much improved since then. Since it's still mainly just me moderating it's hard to tell what's objectively bad vs what just annoys me personally, and to do that I've been keeping an eye on a few forms of content to see how they perform (using mostly votes and comment quantity & health). Based on that the notable changes are: 🚫 Listicles. "7 cool python functions", "14 ways to get promoted". These are usually spammy content farms. If you found 15 amazing open source projects that will blow my mind, post those projects instead. 🚫 Extreme beginner content ("how to write a for loop"). This is difficult to identify objectively (how can you tell it from good articles like "how does kafka work?" or "getting started with linear algebra for ML"?) so there will be some back and forth on calibrating, but there has been a swath of very low quality "tutorials" if you can even call them that, that I very much doubt anybody is actually learning anything from and they sit at 0 points. Since "what is a variable?" is probably not useful to anybody already reading r/programming this is a quick painless way to boost the average quality on the subreddit. ⚠️ Career posts must be related to software engineering careers. To be honest I'm personally not a fan of career posts on r/programming at all (but shout out to cscareerquestions!) but during the last rules revision they were doing pretty well so I know there is an audience for it that I don't want to get in the way of. Since then there has been growth in this category all across the quality spectrum (with an accompanying rise in product management methodology like "agile vs waterfall", also across the quality spectrum). Going forward these posts must be distinctly related to software engineering careers rather than just generic working. This isn't a huge problem yet but I predict that it will be as the percentage of career content is growing. In all of these cases the category is more of a tell that the quality is probably low, so exceptions will be made where that's not the case. These are difficult categories to moderate by so I'll probably make some mistakes on the boundaries and that's okay, let me know and we'll figure it out. Some other categories that I'm keeping an eye on but not ruling on today are: Corporate blogs simply describing their product in the guise of "what is an authorisation framework?" (I'm looking at you Auth0 and others like it). Pretty much anything with a rocket ship emoji in it. Companies use their blogs as marketing, branding, and recruiting tools and that's okay when it's "writing a good article will make people think of us" but it doesn't go here if it's just a literal advert. Usually they are titled in a way that I don't spot them until somebody reports it or mentions it in the comments. Generic AI content that isn't technical in content. "Does Devin mean that programming is over?", "Will AI put farmers out of work?", "Is AI art?". For a few weeks these were the titles of about 20 articles per day, some scoring high and some low. Fashions like this come and go but I'm keeping an eye on it. Newsletters: There are a few people that post every edition of their newsletter to reddit, where that newsletter is really just aggregating content from elsewhere. It's clear that they are trying to grow a monetised audience using reddit, but that's okay if it's providing valuable curation or if the content is good and people like it. So we'll see. Career posts. Personally I'd like r/programming to be a deeply technical place but as mentioned there's clearly an audience for career advice. That said, the posts that are scoring the highest in this category are mostly people upvoting to agree with a statement in the title, not something that anybody is learning from. ("Don't make your engineers context-switch." "Everybody should get private offices." "Micromanaging sucks.") The ones that one could actually learn from with an instructive lean mostly don't do well; people seem to not really be interested in how to have the best 1:1s with their managers or how you went from Junior to Senior in 18 hours (though sometimes they are). That tells me that there's some subtlety to why these posts are scoring well and I'm keeping an eye on the category. What I don't want is for "vote up if you want free snacks" to push out the good stuff or to be a farm for the other 90% of content that's really just personal brand builders. I'm sure you're as annoyed as I am about these but they're fuzzy lines and difficult to come up with objective criteria around. As always I'm looking for feedback on these and if I'm missing any and any other points regarding the subreddit and moderation so let me know what you think. The rules! With all of that, here is the current set of the rules with the above changes included so I can link to them all in one place. ✅ means that it's currently allowed, 🚫 means that it's not currently allowed, ⚠️ means that we leave it up if it is already popular but if we catch it young in its life we do try to remove it early. ✅ Actual programming content. They probably have actual code in them. Language or library writeups, papers, technology descriptions. How an allocator works. How my new fancy allocator I just wrote works. How our startup built our Frobnicator. For many years this was the only category of allowed content. ✅ Academic CS or programming papers ✅ Programming news. ChatGPT can write code. A big new CVE just dropped. Curl 8.01 released now with Coffee over IP support. ✅ Programmer career content. How to become a Staff engineer in 30 days. Habits of the best engineering managers. These must be related or specific to programming/software engineering careers in some way ✅ Articles/news interesting to programmers but not about programming. Work from home is bullshit. Return to office is bullshit. There's a Steam sale on programming games. Terry Davis has died. How to SCRUMM. App Store commissions are going up. How to hire a more diverse development team. Interviewing programmers is broken. ⚠️ General technology news. Google buys its last competitor. A self driving car hit a pedestrian. Twitter is collapsing. Oculus accidentally showed your grandmother a penis. Github sued when Copilot produces the complete works of Harry Potter in a code comment. Meta cancels work from home. Gnome dropped a feature I like. How to run Stable Diffusion to generate pictures of, uh, cats, yeah it's definitely just for cats. A bitcoin VR metaversed my AI and now my app store is mobile social local. 🚫 Politics. The Pirate Party is winning in Sweden. Please vote for net neutrality. Big Tech is being sued in Europe for gestures broadly. Grace Hopper Conference is now 60% male. 🚫 Gossip. Richard Stallman switches to Windows. Elon Musk farted. Linus Torvalds was a poopy-head on a mailing list. The People's Rust Foundation is arguing with the Rust Foundation For The People. Terraform has been forked into Terra and Form. Stack Overflow sucks now. Stack Overflow is good actually. ✅ Demos with code. I wrote a game, here it is on GitHub 🚫 Demos without code. I wrote a game, come buy it! Please give me feedback on my startup (totally not an ad nosirree). I stayed up all night writing a commercial text editor, here's the pricing page. I made a DALL-E image generator. I made the fifteenth animation of A* this week, here's a GIF. 🚫 AskReddit type forum questions. What's your favourite programming language? Tabs or spaces? Does anyone else hate it when. 🚫 Support questions. How do I write a web crawler? How do I get into programming? Where's my missing semicolon? Please do this obvious homework problem for me. Personally I feel very strongly about not allowing these because they'd quickly drown out all of the actual content I come to see, and there are already much more effective places to get them answered anyway. In real life the quality of the ones that we see is also universally very low. 🚫 Surveys and 🚫 Job postings and anything else that is looking to extract value from a place a lot of programmers hang out without contributing anything itself. 🚫 Meta posts. DAE think r/programming sucks? Why did you remove my post? Why did you ban this user that is totes not me I swear I'm just asking questions. Except this meta post. This one is okay because I'm a tyrant that the rules don't apply to (I assume you are saying about me to yourself right now). 🚫 Images, memes, anything low-effort or low-content. Thankfully we very rarely see any of this so there's not much to remove but like support questions once you have a few of these they tend to totally take over because it's easier to make a meme than to write a paper and also easier to vote on a meme than to read a paper. ⚠️ Posts that we'd normally allow but that are obviously, unquestioningly super low quality like blogspam copy-pasted onto a site with a bazillion ads. It has to be pretty bad before we remove it and even then sometimes these are the first post to get traction about a news event so we leave them up if they're the best discussion going on about the news event. There's a lot of grey area here with CVE announcements in particular: there are a lot of spammy security "blogs" that syndicate stories like this. Pretty much all listicles are disallowed under this rule. 7 cool python functions. 14 ways to get promoted. If you found 15 amazing open source projects that will blow my mind, post those projects instead. ⚠️ Extreme beginner content. What is a variable. What is a for loop. Making an HTPT request using curl. Like listicles this is disallowed because of the quality typical to them, but high quality tutorials are still allowed and actively encouraged. ⚠️ Posts that are duplicates of other posts or the same news event. We leave up either the first one or the healthiest discussion. ⚠️ Posts where the title editorialises too heavily or especially is a lie or conspiracy theory. Comments are only very loosely moderated and it's mostly 🚫 Bots of any kind (Beep boop you misspelled misspelled!) and 🚫 Incivility (You idiot, everybody knows that my favourite toy is better than your favourite toy.) However the number of obvious GPT comment bots is rising and will quickly become untenable for the number of active moderators we have. submitted by /u/ketralnis [link] [comments]
Please note that this is a basic cheat sheet and git has many more functionalities and options, it is worth reading the git documentation to learn more.
Clone a project: git clone git_repo_url project_name
Switch to a branch locally: git checkout branch_name
Modify a file, then save and push it to remote repo in current branch git add path_to_file_modifeid/file_name git commit -m “Description of modification” git push
Get a new version of a file after modifying local version git checkout path_to_file_modified/file_modified
Get latest version of current branch git fetch git pull if you have local changes, you will be prompted to commit or stash them before pulling.
Create a new branch based on current branch and switch to it git checkout –b branch_name
Switch to master branch git checkout master
Merge branch_name to master git merge branch_name
Delete local branch git branch -d branch_name
Undo a merge or pull git reset –hard
Undo a commit locally and on the remote branch git reset –hard commit_id git push –force
Get remote url of a local branch git remote show origin
How to declare and write a script with hash tables on windows and linux
A hash table, also known as a hash map, is a data structure that is used to store key-value pairs. It is an efficient way to store data that can be quickly retrieved using a unique key.
Here is an example of how to declare and write a script with a hash table in Python:
# Declare an empty hash table hash_table = {}
# Add some key-value pairs to the hash table hash_table[‘key1’] = ‘value1’ hash_table[‘key2’] = ‘value2’ hash_table[‘key3’] = ‘value3’
# Access a value using its key print(hash_table[‘key2’]) # Output: “value2”
# Modify a value using its key hash_table[‘key2’] = ‘new value’ print(hash_table[‘key2’]) # Output: “new value”
# Delete a key-value pair using the `del` statement del hash_table[‘key1’]
# Check if a key is in the hash table using the `in` operator print(‘key1’ in hash_table) # Output: False
# Output: False
In this example, we declare an empty hash table using the {} syntax. We then add some key-value pairs to the hash table using the [] syntax. We access a value using its key, modify a value using its key, delete a key-value pair using the del statement, and check if a key is in the hash table using the in operator.
I hope this helps! Let me know if you have any questions.
Add new key-value in hashtable: $states.Add(“Manitoba”,”Winnipeg”)
Remove key-value in hashtable: $states.Remove(“Manitoba”,”Winnipeg”) Change value in hashtable: $states.Set_Item(“Ontario”,”Ottawa”) Retrieve value in hashtable: $states.Get_Item(“Alberta”) Find key in hashtable: $states.ContainsKey(“Alberta”) Find Value in hashtable: $states.ContainsValue(“Calgary”) Count items in hashtable: $states.Count Sort items by Name in hashtable: $states.GetEnumerator() | Sort-Object Name -descending Sort items by Value in hashtable: $states.GetEnumerator() | Sort-Object Value -descending
Hash tables with perl on linux or windows
Declaration: my %hash = (); #Initialize a hash my $hash_ref = {}; # Initialize a hash reference. ref will return HASH Clear (or empty) a hash for (keys %hash) { delete $hash{$_}; } Clear (or empty) a hash reference for (keys %$href) { delete $href->{$_}; } Add a key/value pair to a hash $hash{ ‘key’ } = ‘value’; # hash $hash{ $key } = $value; # hash, using variables Using Hash Reference $href->{ ‘key’ } = ‘value’; # hash ref $href->{ $key } = $value; # hash ref, using variables Add several key/value pairs to a hash %hash = ( ‘key1’, ‘value1’, ‘key2’, ‘value2’, ‘key3’, ‘value3’ ); %hash = ( key1 => ‘value1’, key2 => ‘value2’, key3 => ‘value3’, );
Copy a hash my %hash_copy = %hash; # copy a hash my $href_copy = $href; # copy a hash ref Delete a single key/value pair delete $hash{$key}; delete $hash_ref->{$key};
On both Windows and Linux, you can use the grep command in combination with the | (pipe) operator to filter the output of another command. The | operator takes the output of the command on the left and passes it as input to the command on the right.
Here is an example of how to use the grep command with the | operator on both Windows and Linux:
On Linux:
# List all the files in the current directory and filter the output to show only the files that contain the word "example" ls | grep example
On Windows:
# List all the files in the current directory and filter the output to show only the files that contain the word "example" dir | findstr example
In this example, the ls (Linux) or dir (Windows) command lists all the files in the current directory, and the grep (Linux) or findstr (Windows) command filters the output to show only the lines that contain the word “example”.
You can use the grep command with the | operator in combination with other command-line utilities to perform various tasks. For example, you can use the grep command to filter the output of the ps command to show only the processes that contain a particular string in their command line arguments.
Using the rev command: The rev command is a utility that reverses the lines of a file or the characters in a string. To reverse a string, you can use the echo command to pass the string to rev:
echo"string" | rev
Using the sed command: The sed command is a powerful utility that can perform various text transformations. To reverse a string, you can use the sed command with the -r option and the 's/.*(.)/\1/g' expression:
echo"string" | sed -r 's/.*(.)/\1/g'
Using the awk command: The awk command is a programming language that is used for text processing. To reverse a string, you can use the awk command with the {print} action:
echo"string" | awk '{print $1}'
On Windows:
Using the powershell command: The powershell command is a shell that provides a command-line interface for Windows. To reverse a string, you can use the powershell command with the -C option and the '[System.Text.Encoding]::Unicode.GetString([System.Text.Encoding]::Unicode.GetBytes("string"))' expression:
Using the cmd command: The cmd command is the command-line interpreter for Windows. To reverse a string, you can use the cmd command with the for loop:
cmd /c "for /L %i in (1,1,%len%) do @echo !string:~%len%-%i,1!"
These are some ways to reverse a string on Linux and Windows. There are other ways to achieve this, using different utilities or programming languages.
Via shell script on Linux
sh-3.2# vi reverse.sh #### Start Script ##### #!/bin/bash input_string=”$1″ reverse_string=””
input_string_length=${#input_string} for (( i=$input_string_length-1; i>=0; i– )) do reverse_string=”$reverse_string${input_string:$i:1}” done
::—————- :: Calc Var Length ::—————- :: %*=Str to Check :: Returns %Len% :: ————— :StrLen %* set Data=%* for /L %%a in (0,1,80) do ( set Char=!Data:~%%a,1! if not “!Char!”==”” ( set /a Len=%%a+1 ) else (exit /b) ) exit /b
::————— :: Reverse String ::————— :: %* Str to Reverse :: Returns %Reverse% ::—————— :ReverseStr %* set Data=%* call :StrLen %Data% for /L %%a in (!Len!,-1,0) do ( set Char=!Data:~%%a,1! set Reverse=!Reverse!!Char! ) exit /b
Let’s find how to prompt and read input variables from keyboard while executing a script using shell, perl, python, batch and powershell (windows and Linux)
On Linux via shell
read -p “Enter your name: ” name echo “Hi, $name. Let’s be friend!”
On Windows via powershell
$name=read-host “Enter your name:” write-host “Hi $name, Let’s be friend!”
On Windows via batch
Set /p Name=”Enter your name:” echo “Hi %name%, Let’s be friend!”
On Windows or Linux via perl
print “Enter your name “; my $name = ; chomp $name; # Get rid of newline character at the end print “Hello $name, let’s be friend”;
On Windows or Linux via python
name=input(“Enter your name: “) print (“Hello ” + name + ” let’s be friend”)
How to search all files containing a specific string on Linux and Windows?
On Linux
grep -rnw ‘directory’ -e “pattern” grep –include=\*.{txt,log} -rnw ‘directory’ -e “pattern” This will only search for files with .txt or .log extension. grep –exclude=*.txt -rnw ‘directory’ -e “pattern” This will exclude files with .txt extensions.
On Windows
CD Location FINDSTR /L /S /I /N /C:”pattern” *.log
How to browse the internet via command line on Linux and Windows?
On Linux
lynx http://google.ca If you don’t have lynx on your linux installation, you will have to install it. On Linux Red hat, install it like this: yum list lynx (to check the availability of the package) yum -y install lynx (to install the package) you can also use: curl -0 http://yoursite/index.html to get the source code of a specific file.
On Windows
start /max http://google.ca Will open the url using your default browser.
Today I Learned (TIL) You learn something new every day; what did you learn today? Submit interesting and specific facts about something that you just found out here.
submitted by /u/jenesuispashariselon [link] [comments]
Reddit Science This community is a place to share and discuss new scientific research. Read about the latest advances in astronomy, biology, medicine, physics, social science, and more. Find and submit new publications and popular science coverage of current research.