question stringlengths 11 28.2k | answer stringlengths 26 27.7k | tag stringclasses 130
values | question_id int64 935 78.4M | score int64 10 5.49k |
|---|---|---|---|---|
I like the GitHub Mac app, which I use with my GitHub account. I have joined a GitLab project and I was wondering whether I can use the GitHub app with a GitLab repository. I found a post that discuss that the Windows GitHub app works with GitLab and one that show how to add a repo. Both these posts gave me hope that t... | With the mac app, you have to do the clone on the command line. Open a terminal, navigate to directory that you want to be the parent of your local repo, and git clone the repo. As soon as this is done, go into the github mac app and Go to File->Add Local Repo
You can then add the repo directory file picker, and from t... | GitLab | 25,548,236 | 21 |
I have a private repository on a GitLab server and using the SSH I can pull a project using git clone.
But I want to run a script on linux command line directly from the server (more specific, a Drupal / Drush .make file)
I tried to run it using the raw file:
drush make http://server.com/user/project/raw/master/file.ma... | With Chris's valuable help, here is how you can run a script (drupal .make file in my case) from a GitLab server. (Probably it works for GitHub but I didn't test it. Maybe the syntax will be a bit different). (Of course this works for any type of script)
It can be done using the authentication tokens. Here is the docum... | GitLab | 24,207,644 | 21 |
In my gitlab project there are 3 main branches: develop, stage and master.
Each time when updated code is pushed to develop branch, I have to merge it to stage branch and then merge it again to master branch manually.
This doesn't seem efficient.
Is there any way to merge branches automatically when there is no conflic... | There is no way to automate this within GitLab. But you can automate this using GitLab CI.
Be aware that the GitLab CI Runners are independent from GitLab and just get a local copy of a Git repository. So your CI script wont be able to run git merge & git push out of the box.
What you need to do is set up a SSH connect... | GitLab | 67,516,773 | 20 |
We're working on a few project hosted on Gitlab and it would be really convenient for us to have a bot to automate some issues handling.
E.g.: automatically close issues that have been tagged as 'waiting answer from client' more than 20 days ago
I can't find any guide nor tutorial on how doing this, I don't even know i... | Depending on exactly what you want to do, there are a number of options. I've used all of these approaches for different tasks:
If you want to write something from scratch, and have full control over every aspect of the bot's workflow, the python-gitlab library is very nice.
If you want something that mainly responds ... | GitLab | 62,672,281 | 20 |
I currently have two jobs in my CI file which are nearly identical.
The first is for manually compiling a release build from any git branch.
deploy_internal:
stage: deploy
script: ....<deploy code>
when: manual
The second is to be used by the scheduler to release a daily build from develop branch.
scheduled_d... | You can use YAML anchors and aliases to reuse the script.
deploy_internal:
stage: deploy
script:
- &deployment_scripts |
echo "Deployment Started"
bash command 1
bash command 2
when: manual
scheduled_deploy_internal:
stage: deploy
script:
- *deployment_scripts
only:
variable... | GitLab | 61,357,650 | 20 |
I know that there are already countless questions in this direction, but unfortunately I was not able to find the right answer yet. If a post already exists, please just share the link here.
I have several gitlab CI / CD pipelines. The first pipeline uses Terraform to build the complete infrastructure for an ECS cluste... | Ok, for everybody who is interested in an answer. I solved it that way:
I execute the following AWS CLI command in the CICD pipeline
aws ecs update-service --cluster <<cluster-name>> --service <<service-name>> --force-new-deployment --region <<region>>
Not the solution I was looking for but it works.
| GitLab | 60,325,351 | 20 |
Is there any way in GitLab UI to reject a merge request because code has issue?
If not what is the right way to track this?
| I agree with Phil Lucks. In my opinion gitlab is missing functionality. A merge request is a request and as such should be able to be rejected/denied.
The following thread gives insight into the thought process that was going on with Closing a request versus denying one. https://gitlab.com/gitlab-org/gitlab-foss/-/issu... | GitLab | 57,577,180 | 20 |
I'm trying to register a new runner on gitlab following these steps :
https://docs.gitlab.com/runner/register/index.html
But when I enter the url, token and tags, an error message pops-up saying:
ERROR: Registering runner... failed runner=CS-XXX status=couldn't execute POST against https://example.com/api/v4... | you need to use tls-ca-file option during registration or in the configuration of your runner.
Here is an example of non-interactive registration with tls-ca-file option :
gitlab-runner register \
--non-interactive \
--registration-token YOUTOKEN \
--url https://example.com/ \
--tls-ca-file /pat... | GitLab | 55,622,960 | 20 |
Is there a way to restrict merging from a specific branch into other branches? Allow me to explain:
I have a 'testing' branch and a 'master' branch in Gitlab. The team creates feature branches, merges them into 'testing' for approval and then merge the feature branch into 'master' once approved.
Sometimes, it can take ... | To begin, be sure your needs is very normal and traditional.
The answer is ... Yes.
How to prevent merging from a branch to another, setting up a server Git Hook
These are some useful links:
Git Hook explanations in Official Git Book
GitLab server-side Hook explanations
An example with a Git Hook written in Ruby to pr... | GitLab | 53,115,040 | 20 |
I got following error in the Gitlab:
Sorry, we cannot cherry-pick this merge request automatically. This merge request may already have been cherry picked, or a more recent commit may have updated some of its content.
I have branch X from which I have to cherry pick commits to the branch Y. Maybe I have already done c... | I did the cherry picks so that I picked up the merge request commits with commands like this:
git cherry-pick -m 1 <merge request commit hash 1>
git cherry-pick -m 1 <merge request commit hash 2>
...
git cherry-pick -m 1 <merge request commit hash N>
The -m 1 parameter is a little bit cryptical in the documentation, b... | GitLab | 49,670,336 | 20 |
I'm wondering what the -T option in the following command does, cannot see this option in the manual somehow:
$ ssh -T git@gitlab.com
Welcome to GitLab, Simeon !
Could somebody explain?
| I explained before what TTY was: a text terminal is needed when you open an interactive session to a remote server.
But: in the context of a remote Git repository hosting server (GitHub, Gitlab, BitBucket, ...), no remote server will ever allow you to open an interactive session (for security reason)
Then only reason w... | GitLab | 47,245,185 | 20 |
I have a GitLab pipeline that I want to:
Build a Java app
Test using docker-compose
Push to my Docker repository
The primary issue I'm having is that this works:
services:
- docker:dind
docker_test:
stage: docker_test
image: docker:latest
script:
- docker version
The output is printed as expected:
> gitla... | As the information you've added, I hope that this does work:
services:
- docker:dind
docker_test:
stage: docker_test
image: ubuntu:latest
variables:
DOCKER_HOST: "tcp://docker:2375"
script:
- docker version
Alternatively:
services:
- docker:dind
docker_test:
stage: docker_test
image: ubuntu:l... | GitLab | 45,316,098 | 20 |
We are working on Gitlab and each time I start merging a branch, Gitlab makes the option "Remove source branch" checked by default (which is -I think- dangerous).
As I don't guarantee that me or a colleague can forget to uncheck this option and make the mistake of removing the branch, I'm wondering if there is a solut... |
Go to Settings > General > Merge requests
Uncheck the box: Enable 'Delete source branch' option by default
This option is only available for the maintaniner role.
| GitLab | 45,055,731 | 20 |
We are using Gitlab (the gitlab.com free version). My colleague is creating merge requests and we are merging from one branch (development) into another (master). When my colleague merges into master the MR is shown as Merged. I am then running some tests on the merged branch (not done automatically through GL curre... | In Gitlab, the merged status means the relevant commits have been merged and no action is needed.
A closed merge request is one that has been put aside or considered irrelevant. It is therefore not merged into the code base.
Therefore, you only merge MRs when you're happy with the changes and close them if you think th... | GitLab | 43,340,029 | 20 |
I get the following error after installing gitlab..
root@Blase:~# sudo /opt/lampp/lampp start
Starting XAMPP for Linux 7.0.9-1...
XAMPP: Starting Apache...fail.
[XAMPP: Another web server is already running.][1]
XAMPP: Starting MySQL...already running.
I cannot access my localhost/phpmyadmin or any projects folder as... | I had to stop all the services,
$sudo /etc/init.d/apache2 stop
$sudo /etc/init.d/mysql stop
$sudo /etc/init.d/proftpd stop
Then I restarted the server
sudo /opt/lampp/lampp restart
| GitLab | 40,480,843 | 20 |
I have uploaded some files to my Gitlab repository on "gitlab.com" while creating wiki for my private project.
Now my questions are:
Can I see list of the uploaded files?
Is there any way to remove some of them?
Why permission of uploaded file is public? Can I change it to private?
Current version of gitlab is Enterp... | Attached files trough the wiki editor are uploaded to /uploads/. As of GitLab version 8.9.0 you are unable to manage these files (i.e. deleting them).
If you want to manage attached files yourself you can clone the wiki as repository. You can find the clone URL in Wiki -> Git Access. It should look something like this:... | GitLab | 38,228,508 | 20 |
How do I uninstall gitlab?
I deleted the /home/gitlab directory but it still opens up when I browse to my hostname.
| This worked on ubuntu 16.04
sudo apt-get remove gitlab-ce
sudo rm -rf /var/opt/gitlab
--kill all process live
sudo pkill -f gitlab
-- Remove paths
sudo rm -rf /opt/gitlab
sudo rm -rf /etc/gitlab
rm -rf /var/opt/gitlab
| GitLab | 35,796,485 | 20 |
I've been just handed the access to a VPS at work, and I thought of installing GitLab CE on it for better teamwork organisation.
Does the GitLab CE license allow me to do so?
| Yup, it is under the MIT license. There is nothing preventing you from using it for commercial projects. The other editions simply add more features and support.
| GitLab | 30,937,953 | 20 |
I stuck here now for like 2 Days a week.
I've got a CentOs machine with Gitlab4 and gitolite. Everything worked fine for weeks, but suddenly last weekend something strange happend quite all binaries disappeared from the mashine ( like yum, python, ruby, mysql ect. ) i've really no clue how that can happn... After hours... | You mention:
Apr 2 10:19:13 venus shd[15693]: User git not allowed because account is locked
Apr 2 10:19:13 venus sshd[15693]: Failed none for illegal user git from ::ffff:127.0.0.1 port 56906 ssh2
This article mentions:
OpenSSH now checks for locked accounts by default.
On Linux systems, locked accounts are defined... | GitLab | 15,664,561 | 20 |
I have a two private repositories: MyProject, MyProjetUtils.
My project uses the MyProjectUtils as a submodule.
My .gitsubmodules looks like this:
[submodule "MyProjetUtils"]
path = MyProjetUtils
url = git@gitlab.com:MyCompany/MyProjetUtils.git
My .gitlab-ci.yml file looks like this:
default:
image: python:l... | The first link you posted has the solution you are looking for:
When your submodule is on the same GitLab server, you should use relative URLs in your .gitmodules file. Then you can clone with HTTPS in all your CI/CD jobs. You can also use SSH for all your local checkouts.
Assuming that your submodules are in the sam... | GitLab | 68,299,491 | 19 |
I'm currently setting up GitLab CI/CD. We use GitVersion in our project, which throws the following error:
/root/.nuget/packages/gitversiontask/5.3.7/build/GitVersionTask.targets(46,9): error : InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
According to this blog... | By default, runners download your code with a 'fetch' rather than a 'clone' for speed's sake, but it can be configured a number of ways. If you want all jobs in your project's pipeline to be cloned rather than fetched, you can change the default in your CI Settings:
If you don't want all your jobs to clone since it's... | GitLab | 65,686,740 | 19 |
Operating system: Linux
git version: 2.26.2
Git repo provider of my repo: gitlab
Repo provider of the failing submodules: Github
.gitmodules
[submodule "libraries/stb"]
path = libraries/stb
url = https://github.com/nothings/stb.git
branch = master
[submodule "libraries/harfbuzz"]
path = libraries/harfbu... | Just in case, make sure all submodules are initialized:
git submodule update --init --recursive
Then, try the pull --recurse-submodules=true again.
Somehow, activating the traces improve the situation:
git -c trace2.eventTarget=1 pull --recurse-submodules=true
| GitLab | 64,190,258 | 19 |
I want to add a tag when building a Docker image, I'm doing this so far but I do not know how to get the latest tag on the repository being deployed.
docker build -t company/app .
My goal
docker build -t company/app:$LATEST_TAG_IN_REPO? .
| Since you're looking for the "latest" git tag which is an ancestor of the currently building commit you probably want to use
git describe --tags --abbrev=0
to get it and use it like:
docker build -t company/app:$(git describe --tags --abbrev=0) .
Read here for the finer points on git describe
| GitLab | 56,584,835 | 19 |
I have installed and configured:
an on-premises GitLab Omnibus on ServerA running on HTTPS
an on-premises GitLab-Runner installed as Docker Service in ServerB
ServerA certificate is generated by a custom CA Root
The Configuration
I've have put the CA Root Certificate on ServerB:
/srv/gitlab-runner/config/certs/ca.c... | You have two options:
Ignore SSL verification
Put this at the top of your .gitlab-ci.yml:
variables:
GIT_SSL_NO_VERIFY: "1"
Point GitLab-Runner to the proper certificate
As outlined in the official documentation, you can use the tls-*-file options to setup your certificate, e.g.:
[[runners]]
...
tls-ca-file = "/... | GitLab | 53,159,258 | 19 |
I have to migrate from jenkins to gitlab and I would like to be able to use dynamic job names in order to have some information directly in the pipeline summary without having to click on each job etc.... in jenkins we can immediately see the parameters passed to our job and this is not the case in gitlab-ci.
My test r... | As of gitlab 12.9, this can be done using trigger and child pipelines — although a little involved:
Quoting the example from the gitlab doc:
generate-config:
stage: build
script: generate-ci-config > generated-config.yml
artifacts:
paths:
- generated-config.yml
child-pipeline:
stage: test
trigger:
... | GitLab | 52,260,381 | 19 |
I want to change my git mergetool kdiff3 to p4merge. because I'm getting an error on my windows system using kdiff3 mergetool.
/mingw32/libexec/git-core/git-mergetool--lib: line 128: C:\Program
Files\KDiff3\kdiff3: cannot execute binary file: Exec format error
application/config/constants.php seems unchanged.
So... | It is possible your kdiff3 installation is broken since it is not working. Or maybe you tried to edit config file manually and messed its content. why? Because windows executables have .exe extension in general. you may try editing config again.
Anyways, that is not important anymore. This is what you need to use if y... | GitLab | 50,245,867 | 19 |
To reproduce it:
Create issue
Open Merge Request (MR) from the issue
Make changes with multiple commits
Check "squash commits" and Merge the MR
Why on earth this creates TWO commits in history with exactly the same changes?
The commits titles:
Merge branch '123-branch-name' into 'dev'
Full Issue name
What is the po... | Sounds like you create one commit containing your changes (commit Full Issue name) and a merge commit, merging changes from that commit into dev branch.
The merge commit is usually created for every merge request. This can be changed in Settings->Merge Request Settings by choosing e.g. Fast Forward Merge instad of Merg... | GitLab | 50,134,937 | 19 |
My problem is the bash script I created got this error "/bin/sh: eval: line 88: ./deploy.sh: not found" on gitlab. Below is my sample script .gitlab-ci.yml.
I suspect that gitlab ci is not supporting bash script.
image: docker:latest
variables:
IMAGE_NAME: registry.gitlab.com/$PROJECT_OWNER/$PROJECT_NAME
DOCKER_DR... | This is probably related to the fact you are using Docker-in-Docker (docker:dind). Your deploy.sh is requesting /bin/bash as the script executor which is NOT present in that image.
You can test this locally on your computer with Docker:
docker run --rm -it docker:dind bash
It will report an error. So rewrite the first... | GitLab | 49,722,185 | 19 |
This morning I got emails for each of my Gitlab Pages that are hosted on custom domains, saying that the domain verification failed.
That's fine, because I don't think I ever verified them in the first place - good on Gitlab for getting this going.
When I head on over the the Settings>Pages>Domain_Details on each repo,... | The docs (and the verification page) were a little confusing for me. Here's what worked for me, on GoDaddy:
A Record:
Name: @
Value: 35.185.44.232
CNAME:
Name: example.com
Value: username.gitlab.io
TXT Record:
Name: @
Value: gitlab-pages-verification-code=00112233445566778899aabbccddeeff
Verified with Gitlab, and al... | GitLab | 48,913,026 | 19 |
I have two different project repositories: my application repository, and an API repository. My application communicates with the API.
I want to set up some integration and E2E tests of my application. The application will need to use the latest version of the API project when running these tests.
The API project is al... | I've come across this limitation recently and have set up an image that can be re-used to make this a simple build step:
https://gitlab.com/finestructure/pipeline-trigger
So in your case this would look like this using my image:
integration_test
stage: integration_test
image: registry.gitlab.com/finestructure/pipel... | GitLab | 44,336,447 | 19 |
I have a gitlab Repository and I want it to update it on the bitbucket account.
Please provide me steps to follow, so that it can be helpful to me to
migrate it in bitbucket from Gitlab.
| 1) Create the repository in Bitbucket using the UI
2) Clone the Gitlab repository using the "--bare" option
git clone --bare GITLAB-URL
3) Add the Bitbucket remote
cd REPO-NAME
git remote add bitbucket BITBUCKET-URL
4) Push all commits, branches and tags to Bitbucket
git push --all bitbucket
git push --tags bitbucket... | GitLab | 44,106,103 | 19 |
We are facing a problem where we need to run one specific job in gitlab CI. We currently not know how to solve this problem. We have multitple jobs defined in our .gitlab-ci.yml but we only need to run a single job within our pipelines. How could we just run one job e.g. job1 or job2? We can't use tags or branches as a... | You can use a gitlab variable expression with only/except like below and then pass the variable into the pipeline execution as needed.
This example defaults to running both jobs, but if passed 'true' for "firstJobOnly" it only runs the first job.
Old Approach -- (still valid as of gitlab 13.8) - only/except
variables:
... | GitLab | 42,986,385 | 19 |
I'm trying to implement a GitLab continuous integration (CI) pipeline with the following .gitlab-ci.yml file:
image: docker:latest
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables:
DOCKER_DRIVER: overlay
services:
- docker:dind
before_script:
- docker info
- curl... | The problem
This is complex problem.
The docker:latest image is based on alpine (Alpine Linux), which is built using musl-libc. This system is very barebones, and as such doesn't have everything a full-fledged desktop Linux might have. In fact, dynamic executables need to be compiled specifically for this system.
docke... | GitLab | 42,295,457 | 19 |
Question
What is the best way to carry artifacts (jar, class, war) among projects when using docker containers in CI phase.
Let me explain my issue in details, please don't stop the reading... =)
Gitlabs project1
unit tests
etc...
package
Gitlabs project2
unit test
etc...
build (failing)
here I need one artifact... | In GitLab silver and premium, there is the
$CI_JOB_TOKEN available, which allows the following .gitlab-ci.yaml snippet:
build_submodule:
image: debian
stage: test
script:
- apt update && apt install -y unzip
- curl --location --output artifacts.zip "https://gitlab.example.com/api/v4/projects/1/jobs/artifacts/... | GitLab | 39,462,371 | 19 |
Is there a way to set a default assignee for newly cerated issues? All new issues are set to Unassigned. This way no notifications about this issue are sent out unless people set their notification levels to watching. And notification settings can only be set for entire groups or projects you are explicitly set as memb... | I have finally found a solution for this myself. It's possible to implement default assignees using templates and quick actions:
Simply put /assign @username into the templates. This way you can even define multiple default assignees for different kinds of issues.
| GitLab | 35,294,878 | 19 |
I know you can use Github issues on the command line by installing ghi.
ghi
However, is there any way to use similar tools for listing/adding/removing/editing issues of repositories on Gitlab ?
| GLab seems to be a great option.
GLab is an open source Gitlab Cli tool written in Go (golang) to help work seamlessly with Gitlab from the command line. Work with issues, merge requests, watch running pipelines directly from your CLI among other features.
https://github.com/profclems/glab
| GitLab | 31,870,653 | 19 |
I am having troubles when I connect with my repository through Xcode.
I have a Gitlab version (full pre-)installed on TurnkeyLinux Virtual Appliance on a remote server.
In the Gitlab Web interface, I've created a new test user: "testuser" with a password "password" and a new project "testproject". This user was assign... | The user/password would only be needed for an http url, not an ssh one.
When using the http url to add a repo in your XCode Accounts, make sure there is no proxy which would prevent the resolution of the example.com server.
If it is still not working, then, as in "Authentification issue when pushing Xcode project to Gi... | GitLab | 20,266,294 | 19 |
Is there a way I can run GitLab (http://gitlab.org/gitlab-ce) and GitLab CI (http://gitlab.org/gitlab-ci) on a Raspberry Pi device running Raspbian?
I want to have my own internal Git box where I can store code and possibly allow other friends access to upload their code too. Is it possible?
Thanks.
| Official way for the Pi 2
There is a very easy way to install it on the Raspberry Pi 2.
wget https://s3-eu-west-1.amazonaws.com/downloads-packages/raspberry-pi/gitlab_7.9.0-omnibus.pi-1_armhf.deb
sudo dpkg -i gitlab_7.9.0-omnibus.pi-1_armhf.deb
You might prefer to go to the official page in order to get latest version... | GitLab | 19,606,735 | 19 |
How can one create a table on gitlab wiki?
It uses github flavored markdown, and this flavor of markdown support tables but I can't make the following example work:
Colons can be used to align columns.
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | ... | Update: See GitLab 14.1 (July 2021)
Create tables and upload images in the Wiki Content Editor
Create tables and upload images in the Wiki Content Editor
We began improving your wiki editing experience in GitLab 14.0, when we introduced the MVC of a new WYSIWYG Markdown editor.
It supported the most common Markdown fo... | GitLab | 17,604,270 | 19 |
I'm trying to commit my first Git repository to a gitlab instance, which I've set up on a debian-VM. Everything is going to happen via local network. The following commands are shown in gitlab after creating a new repo.
mkdir test
cd test
git init
touch README
git add README
git commit -m 'first commit'
git remote add ... | I've solved my problem. The given port 1337 wasn't the problem, although it was wrong too, because ssh does not seem to be able to handle a port in url:
Using a remote repository with non-standard port
The Git-url which worked for me was:
git@10.200.3.248:repositories/Matt/test.git
My Git user home dir is located in /... | GitLab | 16,912,542 | 19 |
I have an existing Gitolite configuration with many users and repositories. It is setup in the default way as the Gitolite installation guide suggests.
Now I would like to add GitLab to be able to do code reviews and bug tracking.
What's the most convenient way to achieve this?
| Original answer (January 2013)
You can follow the standard installation, and indicate in your gitlab.yml config file the location of your gitolite repo, as well as the gitolite admin user.
However, GitLab requires from the user to register themselves in GitLab and copy their public ssh key.
That means you might need to... | GitLab | 14,523,876 | 19 |
In the gitlab documentation you find a list of predefined variables HERE, where the variable CI_PIPELINE_SOURCE is explained to have the possible values "push, web, schedule, api, external, chat, webide, merge_request_event, external_pull_request_event, parent_pipeline, trigger, or pipeline."
However, it is not explain... | Regarding your first set of questions, i have to point you forward to the gitlab CI Documentation and the rules:if section. They have their a good explanation of the states and also some addtion https://docs.gitlab.com/ee/ci/jobs/job_control.html#common-if-clauses-for-rules - i am just screenshoting this, so people can... | GitLab | 69,734,612 | 18 |
I'm deploying the front-end of my website to amazon s3 via Gitlab pipelines. My previous deployments have worked successfully but the most recent deployments do not. Here's the error:
Completed 12.3 MiB/20.2 MiB (0 Bytes/s) with 1 file(s) remaining
upload failed: dist/vendor.bundle.js.map to s3://<my-s3-bucket-name>/ve... | (I encountered this issue many times - Adding another answer for people that have the same error - from other reasons).
A quick checklist.
Go to Setting -> CI/CD -> Variables and check:
If both AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY environment variables exist.
If both names are spelled right.
If their state is def... | GitLab | 49,814,003 | 18 |
Basically I am looking for the retry button for the pipeline triggered, but all I see is a retry button for the individuals jobs of that pipeline. I don't want to have to push a commit just to retry a pipeline.
Reference screenshot
| You can retry the latest push on the pipeline by going to:
CI/CD -> Pipelines -> Run Pipeline -> Select the branch to run.
Otherwise, as you've mentioned, you'd have to manually press the retry button for each individual job for the pipeline (for a pipeline that isn't the latest).
| GitLab | 49,686,342 | 18 |
I have a GitLab CI docker runner to execute my automated tests when I push. One of my tests requires a custom entry in /etc/hosts. I can't figure out how to get the entry into that file.
Here's basically what my .gitlab-ci.yml file looks like:
before_script:
- cat /etc/hosts # for debugging
- ... # i... | The following statement is incorrect:
"But that just fails because the gitlab-runner user doesn't have permissions to write to that file."
The gitlab-runner is not the user executing your before_script, it is the user that runs the container in which your job is executed.
You are using the ruby:2.5 Docker image as fa... | GitLab | 48,505,986 | 18 |
I'm in the middle of some CocoaPods project trying to build my own private Pod, reachable via "pod install" from my main project.
It's a Swift project, and everything seemed to be working, reading the appropriate tutorials, etc...
I have to say I've been using cocoapods for some time, but I'm kind of new building my ow... | The only thing you need to do is change :path => to :git => and it should download the pod from your repo.
| GitLab | 39,223,846 | 18 |
If there are more than one available runner for a project, how does gitlab ci decide which runner to use?
I have an omnibus gitlab 8.6.6-ee installation, with 2 runners configured. The runners are identical (docker images, config, etc) except that they are running on different computers.
If they are both idle and a job... | To add to Rubinum's answer the 'first' runner would be whichever runner that checks in first that meets all criteria. For example, labels could limit which runners certain jobs run on.
Runners query the gitlab server every X seconds to check if there are builds. if there's a build queued and multiple meet criteria, the... | GitLab | 36,700,653 | 18 |
As the title states, I can't clone a repository from a Gitlab 6 server even though the ssh seems to work.
When trying to clone, it looks like this:
git clone ssh://git@domain.de:1337/project/repository.git
Cloning into 'repository'...
Access denied.
fatal: Could not read from remote repository.
Please make sure you ha... | Try the scp-like syntax:
git clone ssh://git@domain.de:1337:project/repository.git
That forces the use of ~/.ssh/config actually, which means the url can be simplified to gitlab:project/repositoriy.git.
But it turned out to be an ssh key issue in the gitlab server ~gitlab/.ssh/authorized_keys (a bit like in issue 473... | GitLab | 33,837,103 | 18 |
I am using the Omnibus GitLab CE system with LDAP authentication.
Because of LDAP authentication, anyone in my company can sign in to GitLab and a new GitLab user account associated with this user is created (according to my understanding).
I want to modify it so that by default this new user (who can automatically sig... | In newer versions of GitLab >= v7.8 …
This is not a setting in config/gitlab.yml but rather in the GUI for admins.
Simply navigate to https://___[your GitLab URL]___/admin/application_settings/general#js-account-settings, and set Default projects limit to 0.
You can then access individual users's project limit at https... | GitLab | 27,909,176 | 18 |
How do I iterate over the words of a string composed of words separated by whitespace?
Note that I'm not interested in C string functions or that kind of character manipulation/access. I prefer elegance over efficiency. My current solution:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
... | I use this to split string by a delimiter. The first puts the results in a pre-constructed vector, the second returns a new vector.
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
template <typename Out>
void split(const std::string &s, char delim, Out result) {
std::istringstream iss(s)... | Split | 236,129 | 3,361 |
How do I split a list of arbitrary length into equal sized chunks?
See also: How to iterate over a list in chunks.
To chunk strings, see Split string every nth character?.
| Here's a generator that yields evenly-sized chunks:
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
import pprint
pprint.pprint(list(chunks(range(10, 75), 10)))
[[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[20, 21, 22, 23, 24, 25, 26... | Split | 312,443 | 3,126 |
I have this string stored in a variable:
IN="bla@some.com;john@home.com"
Now I would like to split the strings by ; delimiter so that I have:
ADDR1="bla@some.com"
ADDR2="john@home.com"
I don't necessarily need the ADDR1 and ADDR2 variables. If they are elements of an array that's even better.
After suggestions from ... | You can set the internal field separator (IFS) variable, and then let it parse into an array. When this happens in a command, then the assignment to IFS only takes place to that single command's environment (to read ). It then parses the input according to the IFS variable value into an array, which we can then iterate... | Split | 918,886 | 2,942 |
I want to split a string using a delimiter, for example split "004-034556" into two separate strings by the delimiter "-":
part1 = "004";
part2 = "034556";
That means the first string will contain the characters before '-', and the second string will contain the characters after '-'.
I also want to check if the string... | Use the appropriately named method String#split().
String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556
Note that split's argument is assumed to be a regular expression, so remember to escape special characters if necessary.
there are 12 ... | Split | 3,481,828 | 1,934 |
Let's say that I have an Javascript array looking as following:
["Element 1","Element 2","Element 3",...]; // with close to a hundred elements.
What approach would be appropriate to chunk (split) the array into many smaller arrays with, lets say, 10 elements at its most?
| The array.slice() method can extract a slice from the beginning, middle, or end of an array for whatever purposes you require, without changing the original array.
const chunkSize = 10;
for (let i = 0; i < array.length; i += chunkSize) {
const chunk = array.slice(i, i + chunkSize);
// do whatever
}
The last ch... | Split | 8,495,687 | 1,044 |
I need to split a string into newlines in .NET and the only way I know of to split strings is with the Split method. However that will not allow me to (easily) split on a newline, so what is the best way to do it?
| To split on a string you need to use the overload that takes an array of strings:
string[] lines = theText.Split(
new string[] { Environment.NewLine },
StringSplitOptions.None
);
Edit:
If you want to handle different types of line breaks in a text, you can use the ability to match more than one string. This wi... | Split | 1,547,476 | 976 |
In a Bash script, I would like to split a line into pieces and store them in an array.
For example, given the line:
Paris, France, Europe
I would like to have the resulting array to look like so:
array[0] = Paris
array[1] = France
array[2] = Europe
A simple implementation is preferable; speed does not matter. How can... | IFS=', ' read -r -a array <<< "$string"
Note that the characters in $IFS are treated individually as separators so that in this case fields may be separated by either a comma or a space rather than the sequence of the two characters. Interestingly though, empty fields aren't created when comma-space appears in the inp... | Split | 10,586,153 | 952 |
I have a comma-separated string that I want to convert into an array, so I can loop through it.
Is there anything built-in to do this?
For example, I have this string
var str = "January,February,March,April,May,June,July,August,September,October,November,December";
Now I want to split this by the comma, and then store... | const array = str.split(',');
MDN reference, mostly helpful for the possibly unexpected behavior of the limit parameter. (Hint: "a,b,c".split(",", 2) comes out to ["a", "b"], not ["a", "b,c"].)
| Split | 2,858,121 | 904 |
I've been using the Split() method to split strings, but this only appears to work if you are splitting a string by a character. Is there a way to split a string, with another string being the split by parameter?
I've tried converting the splitter into a character array, with no luck.
In other words, I'd like to split ... | In order to split by a string you'll have to use the string array overload.
string data = "THExxQUICKxxBROWNxxFOX";
return data.Split(new string[] { "xx" }, StringSplitOptions.None);
| Split | 2,245,442 | 854 |
I think what I want to do is a fairly common task but I've found no reference on the web. I have text with punctuation, and I want a list of the words.
"Hey, you - what are you doing here!?"
should be
['hey', 'you', 'what', 'are', 'you', 'doing', 'here']
But Python's str.split() only works with one argument, so I ha... | re.split()
re.split(pattern, string[, maxsplit=0])
Split string by the occurrences of pattern. If capturing parentheses are used in pattern, then the text of all groups in the pattern are also returned as part of the resulting list. If maxsplit is nonzero, at most maxsplit splits occur, and the remainder of the string... | Split | 1,059,559 | 842 |
Say I have a string here:
var fullName: String = "First Last"
I want to split the string based on whitespace and assign the values to their respective variables
var fullNameArr = // something like: fullName.explode(" ")
var firstName: String = fullNameArr[0]
var lastName: String? = fullnameArr[1]
Also, sometimes us... | Just call componentsSeparatedByString method on your fullName
import Foundation
var fullName: String = "First Last"
let fullNameArr = fullName.componentsSeparatedByString(" ")
var firstName: String = fullNameArr[0]
var lastName: String = fullNameArr[1]
Update for Swift 3+
import Foundation
let fullName = "First ... | Split | 25,678,373 | 833 |
I found some answers online, but I have no experience with regular expressions, which I believe is what is needed here.
I have a string that needs to be split by either a ';' or ', '
That is, it has to be either a semicolon or a comma followed by a space. Individual commas without trailing spaces should be left untouch... | Luckily, Python has this built-in :)
import re
# Regex pattern splits on substrings "; " and ", "
re.split('; |, ', string_to_split)
Update:
Following your comment:
>>> string_to_split = 'Beautiful, is; better*than\nugly'
>>> import re
>>> re.split('; |, |\*|\n', string_to_split)
['Beautiful', 'is', 'better', 'than',... | Split | 4,998,629 | 794 |
How do I split a string with multiple separators in JavaScript?
I'm trying to split on both commas and spaces, but AFAIK JavaScript's split() function only supports one separator.
| Pass in a regexp as the parameter:
js> "Hello awesome, world!".split(/[\s,]+/)
Hello,awesome,world!
Edited to add:
You can get the last element by selecting the length of the array minus 1:
>>> bits = "Hello awesome, world!".split(/[\s,]+/)
["Hello", "awesome", "world!"]
>>> bit = bits[bits.length - 1]
"world!"
... a... | Split | 650,022 | 767 |
How can you switch your current windows from horizontal split to vertical split and vice versa in Vim?
I did that a moment ago by accident but I cannot find the key again.
| Vim mailing list says (re-formatted for better readability):
To change two vertically split
windows to horizonally split
Ctrl-w t Ctrl-w K
Horizontally to vertically:
Ctrl-w t Ctrl-w H
Explanations:
Ctrl-w t makes the first (topleft) window current
Ctrl-w K moves the current window to full-width at the very ... | Split | 1,269,603 | 710 |
I am parsing a string in C++ using the following:
using namespace std;
string parsed,input="text to be parsed";
stringstream input_stringstream(input);
if (getline(input_stringstream,parsed,' '))
{
// do some processing.
}
Parsing with a single char delimiter is fine. But what if I want to use a string as delim... | You can use the std::string::find() function to find the position of your string delimiter, then use std::string::substr() to get a token.
Example:
std::string s = "scott>=tiger";
std::string delimiter = ">=";
std::string token = s.substr(0, s.find(delimiter)); // token is "scott"
The find(const string& str, size_t p... | Split | 14,265,581 | 687 |
Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for that?
String commaSeparated = "item1 , item2 , item3";
List<String> items = //method that converts above string into list??
| Convert comma separated String to List
List<String> items = Arrays.asList(str.split("\\s*,\\s*"));
The above code splits the string on a delimiter defined as: zero or more whitespace, a literal comma, zero or more whitespace which will place the words into the list and collapse any whitespace between the words and com... | Split | 7,488,643 | 663 |
I'm looking for the Python equivalent of
String str = "many fancy word \nhello \thi";
String whiteSpaceRegex = "\\s";
String[] words = str.split(whiteSpaceRegex);
["many", "fancy", "word", "hello", "hi"]
| The str.split() method without an argument splits on whitespace:
>>> "many fancy word \nhello \thi".split()
['many', 'fancy', 'word', 'hello', 'hi']
| Split | 8,113,782 | 657 |
How do I split a sentence and store each word in a list? e.g.
"these are words" ⟶ ["these", "are", "words"]
To split on other delimiters, see Split a string by a delimiter in python.
To split into individual characters, see How do I split a string into a list of characters?.
| Given a string sentence, this stores each word in a list called words:
words = sentence.split()
| Split | 743,806 | 654 |
I have this string
'john smith~123 Street~Apt 4~New York~NY~12345'
Using JavaScript, what is the fastest way to parse this into
var name = "john smith";
var street= "123 Street";
//etc...
| With JavaScript’s String.prototype.split function:
var input = 'john smith~123 Street~Apt 4~New York~NY~12345';
var fields = input.split('~');
var name = fields[0];
var street = fields[1];
// etc.
| Split | 96,428 | 635 |
What regex pattern would need I to pass to java.lang.String.split() to split a String into an Array of substrings using all whitespace characters (' ', '\t', '\n', etc.) as delimiters?
| Something in the lines of
myString.split("\\s+");
This groups all white spaces as a delimiter.
So if I have the string:
"Hello[space character][tab character]World"
This should yield the strings "Hello" and "World" and omit the empty space between the [space] and the [tab].
As VonC pointed out, the backslash should b... | Split | 225,337 | 594 |
Using SQL Server, how do I split a string so I can access item x?
Take a string "Hello John Smith". How can I split the string by space and access the item at index 1 which should return "John"?
| I don't believe SQL Server has a built-in split function, so other than a UDF, the only other answer I know is to hijack the PARSENAME function:
SELECT PARSENAME(REPLACE('Hello John Smith', ' ', '.'), 2)
PARSENAME takes a string and splits it on the period character. It takes a number as its second argument, and tha... | Split | 2,647 | 533 |
What would be the best way to split a string on the first occurrence of a delimiter?
For example:
"123mango abcd mango kiwi peach"
splitting on the first mango to get:
" abcd mango kiwi peach"
To split on the last occurrence instead, see Partition string in Python and get value of last segment after colon.
| From the docs:
str.split([sep[, maxsplit]])
Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements).
s.split('mango', 1)[1]
| Split | 6,903,557 | 502 |
Why does the second line of this code throw ArrayIndexOutOfBoundsException?
String filename = "D:/some folder/001.docx";
String extensionRemoved = filename.split(".")[0];
While this works:
String driveLetter = filename.split("/")[0];
I use Java 7.
| You need to escape the dot if you want to split on a literal dot:
String extensionRemoved = filename.split("\\.")[0];
Otherwise you are splitting on the regex ., which means "any character".
Note the double backslash needed to create a single backslash in the regex.
You're getting an ArrayIndexOutOfBoundsException be... | Split | 14,833,008 | 483 |
Java has a convenient split method:
String str = "The quick brown fox";
String[] results = str.split(" ");
Is there an easy way to do this in C++?
| The Boost tokenizer class can make this sort of thing quite simple:
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
int main(int, char**)
{
string text = "token, test string";
char_separator<char> sep(", ");
t... | Split | 53,849 | 478 |
I'm trying to split text in a JTextArea using a regex to split the String by \n However, this does not work and I also tried by \r\n|\r|n and many other combination of regexes.
Code:
public void insertUpdate(DocumentEvent e) {
String split[], docStr = null;
Document textAreaDoc = (Document)e.getDocument();
... | This should cover you:
String lines[] = string.split("\\r?\\n");
There's only really two newlines (UNIX and Windows) that you need to worry about.
| Split | 454,908 | 467 |
I have some python code that splits on comma, but doesn't strip the whitespace:
>>> string = "blah, lots , of , spaces, here "
>>> mylist = string.split(',')
>>> print mylist
['blah', ' lots ', ' of ', ' spaces', ' here ']
I would rather end up with whitespace removed like this:
['blah', 'lots', 'of', 'spaces', ... | Use list comprehension -- simpler, and just as easy to read as a for loop.
my_string = "blah, lots , of , spaces, here "
result = [x.strip() for x in my_string.split(',')]
# result is ["blah", "lots", "of", "spaces", "here"]
See: Python docs on List Comprehension
A good 2 second explanation of list comprehension.
| Split | 4,071,396 | 463 |
I need to split my String by spaces.
For this I tried:
str = "Hello I'm your String";
String[] splited = str.split(" ");
But it doesn't seem to work.
| What you have should work. If, however, the spaces provided are defaulting to... something else? You can use the whitespace regex:
str = "Hello I'm your String";
String[] splited = str.split("\\s+");
This will cause any number of consecutive spaces to split your string into tokens.
| Split | 7,899,525 | 451 |
What's the recommended Python idiom for splitting a string on the last occurrence of the delimiter in the string? example:
# instead of regular split
>> s = "a,b,c,d"
>> s.split(",")
>> ['a', 'b', 'c', 'd']
# ..split only on last occurrence of ',' in string:
>>> s.mysplit(s, -1)
>>> ['a,b,c', 'd']
mysplit takes a sec... | Use .rsplit() or .rpartition() instead:
s.rsplit(',', 1)
s.rpartition(',')
str.rsplit() lets you specify how many times to split, while str.rpartition() only splits once but always returns a fixed number of elements (prefix, delimiter & postfix) and is faster for the single split case.
Demo:
>>> s = "a,b,c,d"
>>> s.r... | Split | 15,012,228 | 413 |
Suppose I have the string 1:2:3:4:5 and I want to get its last field (5 in this case). How do I do that using Bash? I tried cut, but I don't know how to specify the last field with -f.
| You can use string operators:
$ foo=1:2:3:4:5
$ echo ${foo##*:}
5
This trims everything from the front until a ':', greedily.
${foo <-- from variable foo
## <-- greedy front trim
* <-- matches anything
: <-- until the last ':'
}
| Split | 3,162,385 | 402 |
I am trying to split the Value using a separator.
But I am finding the surprising results
String data = "5|6|7||8|9||";
String[] split = data.split("\\|");
System.out.println(split.length);
I am expecting to get 8 values. [5,6,7,EMPTY,8,9,EMPTY,EMPTY]
But I am getting only 6 values.
Any idea and how to fix. No matter ... | split(delimiter) by default removes trailing empty strings from result array. To turn this mechanism off we need to use overloaded version of split(delimiter, limit) with limit set to negative value like
String[] split = data.split("\\|", -1);
Little more details:
split(regex) internally returns result of split(regex,... | Split | 14,602,062 | 386 |
I have a Pandas DataFrame with one column:
import pandas as pd
df = pd.DataFrame({"teams": [["SF", "NYG"] for _ in range(7)]})
teams
0 [SF, NYG]
1 [SF, NYG]
2 [SF, NYG]
3 [SF, NYG]
4 [SF, NYG]
5 [SF, NYG]
6 [SF, NYG]
How can split this column of lists into two columns?
Desired result:
team1 team2
0 ... | You can use the DataFrame constructor with lists created by to_list:
import pandas as pd
d1 = {'teams': [['SF', 'NYG'],['SF', 'NYG'],['SF', 'NYG'],
['SF', 'NYG'],['SF', 'NYG'],['SF', 'NYG'],['SF', 'NYG']]}
df2 = pd.DataFrame(d1)
print (df2)
teams
0 [SF, NYG]
1 [SF, NYG]
2 [SF, NYG]
3 [SF, NY... | Split | 35,491,274 | 383 |
Assume I've got some arbitrary layout of splits in vim.
____________________
| one | two |
| | |
| |______|
| | three|
| | |
|___________|______|
Is there a way to swap one and two and maintain the same layout? It's simple in this example, but I'm looking for... | Starting with this:
____________________
| one | two |
| | |
| |______|
| | three|
| | |
|___________|______|
Make 'three' the active window, then issue the command ctrl+w J. This moves the current window to fill the bottom of the screen, leaving you with:
_____... | Split | 2,586,984 | 362 |
I have a multi-line string that I want to do an operation on each line, like so:
inputString = """Line 1
Line 2
Line 3"""
I want to iterate on each line:
for line in inputString:
doStuff()
| inputString.splitlines()
Will give you a list with each item, the splitlines() method is designed to split each line into a list element.
| Split | 172,439 | 357 |
I have a string containing many words with at least one space between each two. How can I split the string into individual words so I can loop through them?
The string is passed as an argument. E.g. ${2} == "cat cat file". How can I loop through it?
Also, how can I check if a string contains spaces?
| I like the conversion to an array, to be able to access individual elements:
sentence="this is a story"
stringarray=($sentence)
now you can access individual elements directly (it starts with 0):
echo ${stringarray[0]}
or convert back to string in order to loop:
for i in "${stringarray[@]}"
do
:
# do whatever on ... | Split | 1,469,849 | 355 |
I'd like to take data of the form
before = data.frame(attr = c(1,30,4,6), type=c('foo_and_bar','foo_and_bar_2'))
attr type
1 1 foo_and_bar
2 30 foo_and_bar_2
3 4 foo_and_bar
4 6 foo_and_bar_2
and use split() on the column "type" from above to get something like this:
attr type_1 type_2
1 ... | Use stringr::str_split_fixed
library(stringr)
str_split_fixed(before$type, "_and_", 2)
| Split | 4,350,440 | 343 |
I have a SQL Table like this:
SomeID
OtherID
Data
abcdef-.....
cdef123-...
18,20,22
abcdef-.....
4554a24-...
17,19
987654-.....
12324a2-...
13,19,20
Is there a query where I can perform a query like SELECT OtherID, SplitData WHERE SomeID = 'abcdef-.......' that returns individual rows, like this:
Ot... | You can use the wonderful recursive functions from SQL Server:
Sample table:
CREATE TABLE Testdata
(
SomeID INT,
OtherID INT,
String VARCHAR(MAX)
);
INSERT Testdata SELECT 1, 9, '18,20,22';
INSERT Testdata SELECT 2, 8, '17,19';
INSERT Testdata SELECT 3, 7, '13,19,20';
INSERT Testdata SELECT 4, 6, '';
... | Split | 5,493,510 | 338 |
I am attempting to split a list into a series of smaller lists.
My Problem: My function to split lists doesn't split them into lists of the correct size. It should split them into lists of size 30 but instead it splits them into lists of size 114?
How can I make my function split a list into X number of Lists of size 3... | I would suggest to use this extension method to chunk the source list to the sub-lists by specified chunk size:
/// <summary>
/// Helper methods for the lists.
/// </summary>
public static class ListExtensions
{
public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize)
{
return source
... | Split | 11,463,734 | 336 |
I would like to split a very large string (let's say, 10,000 characters) into N-size chunks.
What would be the best way in terms of performance to do this?
For instance:
"1234567890" split by 2 would become ["12", "34", "56", "78", "90"].
Would something like this be possible using String.prototype.match and if so, wou... | You can do something like this:
"1234567890".match(/.{1,2}/g);
// Results in:
["12", "34", "56", "78", "90"]
The method will still work with strings whose size is not an exact multiple of the chunk-size:
"123456789".match(/.{1,2}/g);
// Results in:
["12", "34", "56", "78", "9"]
In general, for any string out of which... | Split | 7,033,639 | 319 |
As the title says, I've got a string and I want to split into segments of n characters.
For example:
var str = 'abcdefghijkl';
after some magic with n=3, it will become
var arr = ['abc','def','ghi','jkl'];
Is there a way to do this?
|
var str = 'abcdefghijkl';
console.log(str.match(/.{1,3}/g));
Note: Use {1,3} instead of just {3} to include the remainder for string lengths that aren't a multiple of 3, e.g:
console.log("abcd".match(/.{1,3}/g)); // ["abc", "d"]
A couple more subtleties:
If your string may contain newlines (which you want ... | Split | 6,259,515 | 318 |
I have this string:
"My name is Marco and I'm from Italy"
I'd like to split it, with the delimiter being is Marco and, so I should get an array with
My name at [0] and
I'm from Italy at [1].
How can I do it with C#?
I tried with:
.Split("is Marco and")
But it wants only a single char.
| string[] tokens = str.Split(new[] { "is Marco and" }, StringSplitOptions.None);
If you have a single character delimiter (like for instance ,), you can reduce that to (note the single quotes):
string[] tokens = str.Split(',');
| Split | 8,928,601 | 315 |
I flubbed up my history and want to do some changes to it. Problem is, I have a commit with two unrelated changes, and this commit is surrounded by some other changes in my local (non-pushed) history.
I want to split up this commit before I push it out, but most of the guides I'm seeing have to do with splitting up you... | There is a guide to splitting commits in the rebase manpage. The quick summary is:
Perform an interactive rebase including the target commit (e.g. git rebase -i <commit-to-split>^ branch) and mark it to be edited.
When the rebase reaches that commit, use git reset HEAD^ to reset to before the commit, but keep your wor... | Split | 4,307,095 | 304 |
I have split my windows horizontally. Now how can I return to normal mode, i.e. no split window just one window without cancelling all of my open windows. I have 5 and do not want to "quit", just want to get out of split window.
| Press Control+w, then hit q to close each window at a time.
Update: Also consider eckes answer which may be more useful to you, involving :on (read below) if you don't want to do it one window at a time.
| Split | 4,809,729 | 302 |
I have a list that looks like this:
my_list = [('1','a'),('2','b'),('3','c'),('4','d')]
I want to separate the list in 2 lists.
list1 = ['1','2','3','4']
list2 = ['a','b','c','d']
I can do it for example with:
list1 = []
list2 = []
for i in list:
list1.append(i[0])
list2.append(i[1])
But I want to know if ther... | >>> source_list = [('1','a'),('2','b'),('3','c'),('4','d')]
>>> list1, list2 = zip(*source_list)
>>> list1
('1', '2', '3', '4')
>>> list2
('a', 'b', 'c', 'd')
Edit: Note that zip(*iterable) is its own inverse:
>>> list(source_list) == zip(*zip(*source_list))
True
When unpacking into two lists, this becomes:
>>> list1... | Split | 7,558,908 | 287 |
I need to get the last element of a split array with multiple separators. The separators are commas and space. If there are no separators it should return the original string.
If the string is "how,are you doing, today?" it should return "today?"
If the input were "hello" the output should be "hello".
How can I do this... | There's a one-liner for everything. :)
var output = input.split(/[, ]+/).pop();
| Split | 651,563 | 280 |
I've recently discovered git's patch option to the add command, and I must say it really is a fantastic feature.
I also discovered that a large hunk could be split into smaller hunks by hitting the s key, which adds to the precision of the commit.
But what if I want even more precision, if the split hunk is not small e... | If you're using git add -p and even after splitting with s, you don't have a small enough change, you can use e to edit the patch directly.
This can be a little confusing, but if you carefully follow the instructions in the editor window that will be opened up after pressing e then you'll be fine. In the case you've q... | Split | 6,276,752 | 258 |
I have a string that has numbers
string sNumbers = "1,2,3,4,5";
I can split it then convert it to List<int>
sNumbers.Split( new[] { ',' } ).ToList<int>();
How can I convert string array to integer list?
So that I'll be able to convert string[] to IEnumerable
| var numbers = sNumbers?.Split(',')?.Select(Int32.Parse)?.ToList();
Recent versions of C# (v6+) allow you to do null checks in-line using the null-conditional operator
| Split | 911,717 | 258 |
Consider the following input string:
'MATCHES__STRING'
I want to split that string wherever the "delimiter" __ occurs. This should output a list of strings:
['MATCHES', 'STRING']
To split on whitespace, see How do I split a string into a list of words?.
To extract everything before the first delimiter, see Splitting... | Use the str.split method:
>>> "MATCHES__STRING".split("__")
['MATCHES', 'STRING']
| Split | 3,475,251 | 257 |
I have a String with an unknown length that looks something like this
"dog, cat, bear, elephant, ..., giraffe"
What would be the optimal way to divide this string at the commas so each word could become an element of an ArrayList?
For example
List<String> strings = new ArrayList<Strings>();
// Add the data here so str... | You could do this:
String str = "...";
List<String> elephantList = Arrays.asList(str.split(","));
Basically the .split() method will split the string according to (in this case) delimiter you are passing and will return an array of strings.
However, you seem to be after a List of Strings rather than an array, so the ... | Split | 10,631,715 | 252 |
I have a string
"1,2,3,4"
and I'd like to convert it into an array:
[1,2,3,4]
How?
| >> "1,2,3,4".split(",")
=> ["1", "2", "3", "4"]
Or for integers:
>> "1,2,3,4".split(",").map { |s| s.to_i }
=> [1, 2, 3, 4]
Or for later versions of ruby (>= 1.9 - as pointed out by Alex):
>> "1,2,3,4".split(",").map(&:to_i)
=> [1, 2, 3, 4]
| Split | 975,769 | 243 |
I am looking for a way to easily split a python list in half.
So that if I have an array:
A = [0,1,2,3,4,5]
I would be able to get:
B = [0,1,2]
C = [3,4,5]
| A = [1,2,3,4,5,6]
B = A[:len(A)//2]
C = A[len(A)//2:]
If you want a function:
def split_list(a_list):
half = len(a_list)//2
return a_list[:half], a_list[half:]
A = [1,2,3,4,5,6]
B, C = split_list(A)
| Split | 752,308 | 223 |
I have prepared a simple code snippet in order to separate the erroneous portion from my web application.
public class Main {
public static void main(String[] args) throws IOException {
System.out.print("\nEnter a string:->");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))... | java.lang.String.split splits on regular expressions, and . in a regular expression means "any character".
Try temp.split("\\.").
| Split | 7,935,858 | 216 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.