Working with git from a terminal is more efficient, so here are some basic commands:
1. Get up to date:
git pull
2. Create a new branch locally from dev branch (this is just an example, can be any other branch, like master, etc.)
git checkout -b AI-Task123 dev
(where AI are my initials so we know who owns the branch and Task123 is the task number for tracking)
3. Push branch on github:
git push origin AI-Task123
4. Commit your code:
git commit -m "Your message"
5. Push the code:
git push
Other useful commands:
6. Delete a branch
git branch -D AI-Task123
Reference: https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches
https://stackoverflow.com/questions/4470523/create-a-branch-in-git-from-another-branch
alina.ionescu
Programming, Books and other things I like...
Tuesday, August 13, 2019
Tuesday, July 30, 2019
Kubernetes - how to get container logs inside a pod
A pod can have multiple containers inside. If you want to see the logs there are 2 simple commands to run:
1. kubectl describe po pod-name-1234
This will display information about the pod. Here you will find container name/s.
2. kubectl logs pod-name-1234 -c container-name
This will show logs from container inside the pod.
1. kubectl describe po pod-name-1234
This will display information about the pod. Here you will find container name/s.
2. kubectl logs pod-name-1234 -c container-name
This will show logs from container inside the pod.
Friday, July 19, 2019
Installing Create React App with Typescript
I have found the following very interesting tutorial:
https://medium.com/@rossbulat/how-to-use-typescript-with-react-and-redux-a118b1e02b76
Here are some things that did not work at first.
1. Installing Create React App with Typescript
I had an older version of create-react-app, so it did not install typescript.
So i had to uninstall the global version and reinstall so that npx always takes the latest version:
npm uninstall -g create-react-app
npx create-react-app app_name --typescript
As described: https://facebook.github.io/create-react-app/docs/getting-started
2. Installing TSLint-React
I am using VSCode and when i run tslint --init i got this error:
tslint : The term 'tslint' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
I had to install like this:
npm install -g tslint typescript tslint-react
tslint --init
https://medium.com/@rossbulat/how-to-use-typescript-with-react-and-redux-a118b1e02b76
Here are some things that did not work at first.
1. Installing Create React App with Typescript
I had an older version of create-react-app, so it did not install typescript.
So i had to uninstall the global version and reinstall so that npx always takes the latest version:
npm uninstall -g create-react-app
npx create-react-app app_name --typescript
As described: https://facebook.github.io/create-react-app/docs/getting-started
2. Installing TSLint-React
I am using VSCode and when i run tslint --init i got this error:
tslint : The term 'tslint' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
I had to install like this:
npm install -g tslint typescript tslint-react
tslint --init
Saturday, June 29, 2019
Start with Django on Windows
1. Install Python:
Download and install from here: https://www.python.org/downloads/
Check python is install by running following command in a CMD.
python -V
should display something like:
Python 3.7.3
2. Create virtual environment.
Create a new folder for your project:
mkdir myproject
Go to the newly created folder:
cd myproject
Run following command (the . at the end means you want to use current directory for virtualenv installation, so don't foget about it):
virtualenv .
Check virtualenv was installed by running the following command:
dir
You should see something like this:
3. Activate virtual environment
Scripts\activate
You will see the name of your virtual environment (myproject) in our case in front of every line in the terminal.
To deactivate you can simply run:
Scripts\deactivate
4. Install Django in this isolated virtual environment:
Make sure the virtual environment is activated and run:
pip install django
5. Check django was installed in your virtual environment:
pip freeze
you should see something like this:
If you see more things installed it means your virtual environment was not activated before installing django, and you have installed it locally on your PC not on the virtual environment.
6. Create new project.
Create a scr folder and move inside it:
mkdir src
cd src
run the following command to start the project (again . means current directory):
django-admin startproject trydjango .
run dir command to see what happened, you should see a folder structure like this:
run following command to run your server:
python manage.py runserver
you should see something like this:
7. Open it in your browser: http://localhost:8000/
8. Connect a db:
python manage.py migrate
9. Create superuser:
python manage.py createsuperuser
Connect to http://localhost:8000/admin with your new user and password.
10. Split your app into components. Create first component:
python manage.py startapp products
11. Create Products model:
12. Update db. This is done everytime you change something:
python manage.py makemigrations
python manage.py migrate
If you go to http://localhost:8000/admin you will see a new sction Products.
13. Work with python shell:
python manage.py shell
14. Meaning of blank and null:
'null=True' means the field can be empty/null in the database while 'null=False' means the field cannot be empty/null in the database.
15. Create a view:
in views.py
in urls.py
16. Create templates:
Create a folder templates and inside it a home.html with some html, then change views.py like this:
17. Inheritance.
Create base.html
make it appear in all pages. home.html example:
18. Include something on every page:
19. Adding and working with context:
in views.py
in about.html
20. Working with forms:
create forms.py
in products/views.py
in products/templates/products/product_create.html
21. Class based views:
blog/views.py
Reference: https://www.youtube.com/watch?v=F5mRW0jo-U4
Download and install from here: https://www.python.org/downloads/
Check python is install by running following command in a CMD.
python -V
should display something like:
Python 3.7.3
2. Create virtual environment.
Create a new folder for your project:
mkdir myproject
Go to the newly created folder:
cd myproject
Run following command (the . at the end means you want to use current directory for virtualenv installation, so don't foget about it):
virtualenv .
Check virtualenv was installed by running the following command:
dir
You should see something like this:
3. Activate virtual environment
Scripts\activate
You will see the name of your virtual environment (myproject) in our case in front of every line in the terminal.
To deactivate you can simply run:
Scripts\deactivate
4. Install Django in this isolated virtual environment:
Make sure the virtual environment is activated and run:
pip install django
5. Check django was installed in your virtual environment:
pip freeze
you should see something like this:
If you see more things installed it means your virtual environment was not activated before installing django, and you have installed it locally on your PC not on the virtual environment.
6. Create new project.
Create a scr folder and move inside it:
mkdir src
cd src
run the following command to start the project (again . means current directory):
django-admin startproject trydjango .
run dir command to see what happened, you should see a folder structure like this:
run following command to run your server:
python manage.py runserver
you should see something like this:
7. Open it in your browser: http://localhost:8000/
8. Connect a db:
python manage.py migrate
9. Create superuser:
python manage.py createsuperuser
Connect to http://localhost:8000/admin with your new user and password.
10. Split your app into components. Create first component:
python manage.py startapp products
11. Create Products model:
from django.db import models
# Create your models here.
class Product(models.Model):
title = models.TextField()
description = models.TextField()
price = models.TextField()
12. Update db. This is done everytime you change something:
python manage.py makemigrations
python manage.py migrate
If you go to http://localhost:8000/admin you will see a new sction Products.
13. Work with python shell:
python manage.py shell
14. Meaning of blank and null:
models.TextField(blank=True, null=True)
'blank=False' means field is required while 'blank=True' means field is not required'null=True' means the field can be empty/null in the database while 'null=False' means the field cannot be empty/null in the database.
15. Create a view:
in views.py
def home_view(*args, **kwargs):
return HttpResponse("<h1>Hello world!</h1>")
in urls.py
from pages.views import home_view
urlpatterns = [
path('admin/', admin.site.urls),
path('', home_view, name='home'),
]
16. Create templates:
Create a folder templates and inside it a home.html with some html, then change views.py like this:
def home_view(request, *args, **kwargs):
return render(request, "home.html", {})
17. Inheritance.
Create base.html
<!DOCTYPE html>
<html>
<head>
<title>TryDjango</title>
</head>
<body>
<h1>Nav bar</h1>
{% block content %}
replace me
{% endblock %}
</body>
</html>
make it appear in all pages. home.html example:
{% extends 'base.html' %}
{% block content %}
<h1> Hello world!</h1>
{{ request.user }}
{{ request.user.is_authenticated }}
{% endblock %}
18. Include something on every page:
{% include 'navbar.html' %}
19. Adding and working with context:
in views.py
def about_view(request, *args, **kwargs):
my_context = {
"my_text": "This is about me",
"this_is_true": True,
"my_number": 123,
"my_list": [123, 456, 789, "abc"]
}
return render(request, "about.html", my_context)
in about.html
<ul>
{% for my_sub_item in my_list %}
{% if my_sub_item == 456 %}
<li>{{ forloop.counter }} - {{ my_sub_item|add:22 }}</li>
{% elif my_sub_item == "abc" %}
<li>This is not ok</li>
{% else %}
<li>{{ forloop.counter }} - {{ my_sub_item }}</li>
{% endif %}
<li>{{ forloop.counter }} - {{ my_sub_item }}</li>
{% endfor %}
</ul>
20. Working with forms:
create forms.py
from django import forms
from .models import Product
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = [
'title',
'description',
'price'
]
in products/views.py
def product_create_view(request):
form = ProductForm(request.POST or None)
if form.is_valid():
form.save()
form.ProductForm()
context = {
'form': form
}
return render(request, "products/product_create.html", context)
in products/templates/products/product_create.html
{% extends 'base.html' %}
{% block content %}
<form method='POST'> {% csrf_token %}
{{ form.as_p }}
<input type='submit' value='Save' />
</form>
{% endblock %}
21. Class based views:
blog/views.py
from django.shortcuts import render, get_object_or_404
from django.views.generic import (
CreateView,
DetailView,
ListView,
UpdateView,
DeleteView
)
from .models import Article
# Create your views here.
class ArticleListView(ListView):
template_name = 'articles/article_list.html'
queryset = Article.objects.all() # <blog>/<modelname>_list.html
class ArticleDetailView(DetailView):
template_name = 'articles/article_detail.html'
# queryset = Article.objects.all()
def get_object(self):
id_ = self.kwargs.get("id")
return get_object_or_404(Article, id=id_)
Reference: https://www.youtube.com/watch?v=F5mRW0jo-U4
Wednesday, March 14, 2018
Spring Boot - Redirect ?wsdl to .wsdl
1. Create urlrewrite.xml under: /src/main/resources
2. Add to your @Configuration file.
3. Run the application and test it works bu accessing: http://localhost:8080/rewrite-status
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite
PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite3.0.dtd">
<urlrewrite>
<rule>
<from>/ws/services?wsdl</from>
<to>/ws/services.wsdl</to>
</rule>
</urlrewrite>
2. Add to your @Configuration file.
@Bean
public FilterRegistrationBean tuckeyRegistrationBean() {
final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new UrlRewriteFilter());
registrationBean.addInitParameter("confPath", "urlrewrite.xml");
return registrationBean;
}
3. Run the application and test it works bu accessing: http://localhost:8080/rewrite-status
Tuesday, February 6, 2018
Selenium - debug your tests in docker container
Do you have UI selenium tests running in a docker container? And if something fails, how easy it is to find the problem?
Here is something that works nicely:
1. I am using VirtualBox and I have an Ubuntu Linux machine with UI with docker and docker-compose installed.
2. Create a docker-compose.yml file:
From here on you can run and debug your tests inside a local container and see what is happening.
I got this hint from a colleague and it was really helpful. I hope it helps you too :)
Here is something that works nicely:
1. I am using VirtualBox and I have an Ubuntu Linux machine with UI with docker and docker-compose installed.
2. Create a docker-compose.yml file:
version: '2'
services:
hub:
image: selenium/hub:3.8.1
ports:
- "4444:4444"
firefox:
image: selenium/node-firefox-debug:3.8.1
volumes:
- /dev/shm:/dev/shm
privileged: true
dns:
- <your dns IP>
environment:
- TZ=DE
- HUB_PORT_4444_TCP_ADDR=hub
- HUB_PORT_4444_TCP_PORT=4444
depends_on:
- hub
ports:
- 5900
3. Open a terminal at the location of your docker-compose.yml file and deploy the selenium hub and firefox node locally, using following command:
docker-compose up
4. Check the Selenium hub and the Firefox node have started:
docker ps -a
5. Go to the VirtualBox VM Settings -> Network -> Advanced -> Port Forwarding -> and create a new rule so that you can access the container ports highlighted in green in previous image ()both Firefox node and Selenium Hub.
6. Install VNC Viewer:
7. Go to Chrome apps and start it: chrome://apps/
8. Enter localhost:5900 -> Connect -> Password is: secret
9. Here is your container.
10. Last thing you have to do is add this line to your testng.xml (I am using testng). On your local machine project in IntelliJ.
<parameter name="hubUrl" value="http://localhost:4444/wd/hub"/>
From here on you can run and debug your tests inside a local container and see what is happening.
I got this hint from a colleague and it was really helpful. I hope it helps you too :)
Sunday, January 28, 2018
"gem install jekyll" fails on Windows 10
Getting this error when trying to install jekyll on Windows?
gem install jekyll
Building native extensions. This could take a while...
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
Here is a solution that worked for me:
1. Download Ruby 2.3 (not going to work with higher version) according to your OS architecture 32 or 64 bit.
https://rubyinstaller.org/downloads/
2. Run the installer to install ruby. After the installer finishes you will have something like this: C:\Ruby23-x64
You can also check the installation by opening a cammand prompt window and typing:
ruby -v
3. From the same site download DevKit.
4. Double-click on the DevKit archive and extract it to something like C:\DevKit.
5. Open a command prompt and navigate to C:\DevKit.
6. Check your C:\DevKit\config.yml file contains reference to your ruby installation.
7. Run ruby dk.rb init followed by ruby dk.rb install
8. Test DevKit installation by running:
gem install json --platform=ruby. JSON
should install correctly and you should see with native extensions in the screen messages.
Next run
ruby -rubygems -e "require 'json'; puts JSON.load('[42]').inspect"
to confirm that the json gem is working
9. Install jekyll:
gem install jekyll
10. test jekyll installation:
jekyll -v
Subscribe to:
Posts (Atom)