camelCase
PascalCase
snake_case
kebab-case
(source: Medium)
Wednesday, December 4, 2019
Sunday, August 11, 2019
Idea: Search for .gitconfig in parent folders until found
I manage multiple git remote accounts on a single machine and each has a different user name and user email associated with it.
Forgetting to set the name and email in a newly pulled repo has caused me trouble quite a lot.
It would be so nice, if I could just have one .gitconfig file sitting in each folder that I use to store the repos associated with a single account, and git would just read the nearest config it finds.
Forgetting to set the name and email in a newly pulled repo has caused me trouble quite a lot.
It would be so nice, if I could just have one .gitconfig file sitting in each folder that I use to store the repos associated with a single account, and git would just read the nearest config it finds.
Sunday, July 28, 2019
Getting started with Ruby (on Rails)
Ruby language basics
- Ruby in 20 minutes
- the Ruby REPL is
irb
- expressions in a string are escaped with
"#{expression}"
- print function is
puts
- functions are defined like:
def myfun(somearg = "default") # do something with somearg end
- arguments can have default value
- functions can be called like:
myfun myfun() myfun "some other arg" myfun("some other arg")
- classes are defined like:
class MyClass attr_accessor :somearg def initialize(somearg = "default") @somearg = somearg end # do something with @somearg anywhere in the class end
- class instantiation is done with the "new" keyword:
myclass = MyClass.new("some other arg")
- the instance variable
@somearg
is private - the methods defined in the class are public by default
- the attribute accessor
:somearg
allows to get and set the instance variable (public). Usage:myclass.somearg
andmyclass.somearg= "something new"
- information about a class can be retrieved with
MyClass.instance_methods(show_inherited = true)
- See more on Ruby-Doc
- iterations
- for each loop
@names.each do |name| puts "Hello #{name}!" end
- conditionals
- if-else block
def say_bye if @names.nil? puts "..." elsif @names.respond_to?("join") # Join the list elements with commas puts "Goodbye #{@names.join(", ")}. Come back soon!" else puts "Goodbye #{@names}. Come back soon!" end end
- @/@@ vs. self
- method visibility
- variables vs constants
- ! (aka. bang) in method names means danger
- ? is indicating a boolean return type
Ruby on Rails basics
- Getting started with Ruby on Rails explains the project structure
- ActiveRecord Basics explains that
- anything that subclasses ApplicationRecord is mapped to a database table
- validations are a thing of ApplicationRecord. See more here.
- ActiveRecord Migrations explains how database migrations are done
rspec testing framework basics
...coming up...in the meantime here are some resources:
- https://dev.to/hanachin/how-to-minimize-rspec-describecontext-nesting-4179
- http://www.betterspecs.org/
- https://stackoverflow.com/questions/5359558/when-to-use-rspec-let
My IDE choice
- VSCode with extensions:
- Ruby
- Ruby Solargraph
- ruby-rubocop
- lourenci.go-to-spec
Monday, July 1, 2019
Developing Gitlab: Setting up a development environment with Vagrant
FYI, I abandoned the Vagrant approach in favor of a VirtualBox machine with Ubuntu.
---
Versions in use:
---
Versions in use:
- Vagrant 2.2.4
- VirtualBox 6.0.8-130520
- gitlab-development-kit revision e519656ac3101770622d9451f500a6c2a08c5250
Set up GDK for the first time
- open a CMD with "Run as Administrator" (aka. "elevated") in the
gitlab-development-kit
directory - follow instructions for Vagrant installation:
vagrant up --provider=virtualbox --provision
Troubleshooting - needed to install vagrant-disksize plugin (provisioning failed with the error: Unknown configuration section 'disksize'.)
- needed to install vagrant-vbguest plugin (provisioning failed with an error for synching directories with rsync)
- when ready:
vagrant ssh
cd gitlab-development-kit
- follow instructions from gdk install: Option 1 develop in fork
gdk install gitlab_repo=https://gitlab.com/MY-FORK/gitlab-ce.git
Troubleshooting - fix line endings (because the repo was cloned on a Windows host with windows line endings, but is used on linux)
- set the git line endings to retrieve any updates unix style for the gdk repo
git config core.autocrlf input
- install dos2unix on the virtual machine
sudo apt-get install dos2unix
- change the line endings in the
support
andbin
directoriescd support find ./ -type f -exec dos2unix {} \; cd .. cd bin find ./ -type f -exec dos2unix {} \; cd ..
- Set up tracking of original upstream repo
support/set-gitlab-upstream
- run the server
gdk run
Troubleshooting - if the run command fails, stop node manually before trying again
pkill -f node gdk run
- reach it from the Host on
localhost:3000
and use the given credentials
There's also a Troubleshooting page, if it is needed.
Here are some more hints:
Here are some more hints:
- A possible fix for
recipe for target 'postgresql/data' failed
- Another possible solution: https://gitlab.com/gitlab-org/gitlab-development-kit/issues/313
- And this one: https://gitlab.com/gitlab-org/gitlab-development-kit/issues/354
Everyday commands
vagrant up
: starts the virtual machinevagrant ssh
: connects the virtual machinecd gitlab-development-kit
gdk run
: starts the serverCtrl+C
: exits the serverCtrl+D
: exits the virtual machinevagrant halt
: stops the virtual machine- How to put a process into background
Restart the whole thing because something went amiss
- clean your git repos from untracked and ignored files and directories
- use
git clean -ndx
to see what would be deleted - use
git clean -fdx
to actually do the deletion - don't worry, repositories within a repository are not cleaned by git clean.
there are 3 repositories in gitlab-development-kit: gitlab-development-kit/gitlab
gitlab-development-kit/gitlab-workhorse/src/gitlab.com/gitlab-org/gitlab-workhorse
gitlab-development-kit/go-gitlab-shell/src/gitlab.com/gitlab-org/gitlab-shell
- delete these directories too:
gitlab-development-kit/gitlab-workhorse/src
gitlab-development-kit/go-gitlab-shell
- do the "Set up GDK for the first time" part again
Thursday, January 31, 2019
Updating from IntelliJ IDEA Community to Ultimate
- export settings from Community and import them to Ultimate
(see https://intellij-support.jetbrains.com/hc/en-us/community/posts/206858965-Import-Settings-from-Community-Edition-into-Professional-Edition) - install any plugin you had in Community that you miss, like:
- Lombok plugin
- VueJS plugin
(see https://www.jetbrains.com/help/idea/vue-js.html) - Markdown file previewer
- Java dependency analyzer
- add sytax highlighting for any non-default files you usually use, like:
- Groovy sytax highlighting to Jenkinsfile (Settings > Editor > File types > Groovy > add "Jenkinsfile*" )
(see https://stackoverflow.com/questions/47796757/jenkinsfile-syntax-highlighting-in-java-project-using-intellij-idea)
Tuesday, January 22, 2019
Updating to Maven 3.6.0
On Ubuntu 16.04
Default state:- installation directory is: /usr/share/maven
- version is 3.3.9
- download newest version of maven (bin tar.gz) from https://maven.apache.org/download.cgi
- unpack to /opt folder (the folder for installing unbundled independent applications)
sudo tar xvf apache-maven-*.tar.gz --directory /opt
- add environmental variables (see also: official reference):
- create script file to set the variables system wide:
sudo gedit /etc/profile.d/maven.sh
- add these lines and save it (change jdk path if needed):
## Environmental variables needed by Maven export JAVA_HOME=/usr/lib/jvm/jdk-11.0.2/
- set the file executable
sudo chmod +x /etc/profile.d/maven.sh
- log out and log in again to see its effect
- update alternatives for the specific new version (change path if needed)
sudo update-alternatives --install "/usr/bin/mvn" "mvn" "/opt/apache-maven-3.6.0/bin/mvn" 100 sudo update-alternatives --set mvn /opt/apache-maven-3.6.0/bin/mvn
On Windows 10
- download newest version of maven (bin zip) from https://maven.apache.org/download.cgi
- unpack zip to "C:\Program Files\Apache\"
- add "C:\Program Files\Apache\apache-maven-3.6.0\bin\" to Path environmental variable, or replace older maven version in Path variable with new one
- log out and log in for the environmental variable to take effect
Note: the M2_HOME and MAVEN_HOME environmental variables are not needed.
Friday, January 18, 2019
Updating to OpenJDK 11
Download OpenJDK's JDK 11 from https://jdk.java.net/11/
On Windows (10):
On Windows (10):
- extract zip to Program Files/Java/
- change JAVA_HOME environmental variable to point to the new JDK
On Ubuntu (16.04) for version 11.0.2:
- unpack tar.gz to /usr/lib/jvm/ (command taken from OpenJDK installation guide)
sudo tar xvf openjdk-11*_bin.tar.gz --directory /usr/lib/jvm/
- update alternatives to be able to switch between other java installations (command taken from DZone guide)
sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.2/bin/*; do update-alternatives --install /usr/bin/$(basename $bin) $(basename $bin) $bin 100; done' sudo sh -c 'for bin in /usr/lib/jvm/jdk-11.0.2/bin/*; do update-alternatives --set $(basename $bin) $bin; done'
- don't forget to update the JAVA_HOME environmental variable if you use maven
Thursday, January 10, 2019
CSS: frequently used selectors
Basic selectors
Wildcard selector: selects all elements* {}
Type selector: selects all elements of the given typediv {}
Attribute selector ([]): selects all elements that has the given attribute[src] {}
ID selector (#): selects the element with the given ID attribute#menu {} /* or [id="menu"] {} */
Class selector (.): selects all elements with the given class attribute.centered {} /* or [class~="centered"] {} */
Selector grouping
selector grouping (,): enables to specify common values in one place
div, #menu, .centered {}
Selector chaining
Selector chainingdiv.#menu.centered[name="Menu"]:first-child::first-letter {}
Attribute value selectors
[attribute="value"] selector: selects all elements with the specified attribute and value[target="_blank"] {}
[attribute~="value"] selector: selects all elements whose attribute value contains the specified whole word.[title~="flower"] {}
[attribute|="value"] selector: selects all elements whose attribute value starts with the specified value, the value being a whole word or the first part of a hyphenated word.[class|="top"] {}
[attribute^="value"] selector: selects all elements whose attribute value begins with the specified value. (like in regex)[class^="top"] {}
[attribute$="value"] selector: selects all elements whose attribute value ends with the specified value. (like in regex)[class$="test"] {}
[attribute*="value"] selector: selects all elements whose attribute value contains the specified value.[class*="te"] {}
Selector combination
Descendant selector (space): matches all elements that are descendants of a specified elementdiv p {}
Child selector (>): selects all elements that are the immediate children of a specified elementdiv > p {}
Adjacent sibling selector (+): selects all elements that are the adjacent siblings of a specified elementdiv + p {}
General sibling selector (~): selects all elements that are siblings of a specified elementdiv ~ p {}
Subscribe to:
Posts (Atom)