piątek, 29 grudnia 2017

rsync poprzez ssh

Odświeżanie lokalnego katalogu na podstawie zasobów zdalnej maszyny:
rsync -r -a -v -e ssh --delete remoteuser@X.X.X.X:/home/remoteuser/testfolder /home/localuser/testfolder

Odświeżanie katalogu zdalnej maszyny na podstawie lokalnych zasobów:
rsync -r -a -v -e ssh --delete /home/localuser/testfolder remoteuser@X.X.X.X:/home/remoteuser/testfolder

Podziel się:

wtorek, 26 grudnia 2017

niedziela, 24 grudnia 2017

VNC na linuksie (dowolna dystrybucja)

Instalujemy pakiety:

sudo apt-get install x11vnc vnc-java

Generujemy hasło dostępu:
x11vnc -storepasswd

Jeśli korzystamy z firewall'a to otwieramy porty 5800 i 5900
Uruchomienie usługi:
x11vnc -forever -usepw -httpdir /usr/share/vnc-java/ -httpport 5800

Dodanie do autostart - wklejamy powyższą komendę zależnie od dystrybucji w odpowiednie miejsce.
Lubuntu:
/etc/xdg/lxsession/Lubuntu/autostart
dodajemy wpis:
@x11vnc -forever -usepw -httpdir /usr/share/vnc-java/ -httpport 5800

Dla elementaryos w System settings. 
Podziel się:

wtorek, 28 listopada 2017

Łatwe proxy w python'ie

Potrzebujemy pythonąa i dodatkowo python-argparse

#!/usr/bin/python
# This is a simple port-forward / proxy, written using only the default python
# library. If you want to make a suggestion or fix something you can contact-me
# at voorloop_at_gmail.com
# Distributed over IDC(I Don't Care) license
import socket
import select
import time
import sys

# Changing the buffer_size and delay, you can improve the speed and bandwidth.
# But when buffer get to high or delay go too down, you can broke things
buffer_size = 4096
delay = 0.0001
forward_to = ('HOST_IP', PORT)

class Forward:
    def __init__(self):
        self.forward = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    def start(self, host, port):
        try:
            self.forward.connect((host, port))
            return self.forward
        except Exception, e:
            print e
            return False

class TheServer:
    input_list = []
    channel = {}

    def __init__(self, host, port):
        self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.server.bind((host, port))
        self.server.listen(200)

    def main_loop(self):
        self.input_list.append(self.server)
        while 1:
            time.sleep(delay)
            ss = select.select
            inputready, outputready, exceptready = ss(self.input_list, [], [])
            for self.s in inputready:
                if self.s == self.server:
                    self.on_accept()
                    break

                self.data = self.s.recv(buffer_size)
                if len(self.data) == 0:
                    self.on_close()
                else:
                    self.on_recv()

    def on_accept(self):
        forward = Forward().start(forward_to[0], forward_to[1])
        clientsock, clientaddr = self.server.accept()
        if forward:
            print clientaddr, "has connected"
            self.input_list.append(clientsock)
            self.input_list.append(forward)
            self.channel[clientsock] = forward
            self.channel[forward] = clientsock
        else:
            print "Can't establish connection with remote server.",
            print "Closing connection with client side", clientaddr
            clientsock.close()

    def on_close(self):
        print self.s.getpeername(), "has disconnected"
        #remove objects from input_list
        self.input_list.remove(self.s)
        self.input_list.remove(self.channel[self.s])
        out = self.channel[self.s]
        # close the connection with client
        self.channel[out].close()  # equivalent to do self.s.close()
        # close the connection with remote server
        self.channel[self.s].close()
        # delete both objects from channel dict
        del self.channel[out]
        del self.channel[self.s]

    def on_recv(self):
        data = self.data
        # here we can parse and/or modify the data before send forward
        print data
        self.channel[self.s].send(data)

if __name__ == '__main__':
        server = TheServer('', 8000)
        try:
            server.main_loop()
        except KeyboardInterrupt:
            print "Ctrl C - Stopping server"
            sys.exit(1)

Podziel się:

niedziela, 5 listopada 2017

samba - przykładowa konfiguracja

[global]
workgroup = smb
security = user
map to guest = Bad Password

[homes]
comment = Home Directories
browsable = no
read only = no
create mode = 0750

[public]
path = /home/user/dir
public = yes
writable = yes
comment = MyDir
printable = no
guest ok = yes
Podziel się:

Ruż do sushi

500 ml ryżu
600 ml wody
60 ml octu do sushi (lub ryżowego)
1,5 łyżki curku
1 łyżeczka soli

Ryż płukamy delikatnie, odsączamy. Gotujemy 10 minut na minimalnym ogniu, po upływie tego czasu wyłączamy gaz i pozostawiamy na kolejne 10 minut przykryty. Ocet mieszamy z cukrem i solą. Do mokrej miski wyrzucamy z garnka ryż, polewamy sosem. Ryż w misce "pociąć" żeby pozbyć się grudek.
Podziel się:

wtorek, 31 października 2017

poniedziałek, 30 października 2017

wtorek, 24 października 2017

wtorek, 3 października 2017

Skróty klawiaturowe w elementaryos

Skróty klawiaturowe możemy skonfigurować otwierając dedykowany w tym celu edytor: Ustawienia systemu -> Klawiatura i zakładka Skróty.
Niektórych jednak tutaj nie ustawimy bo mamy systemowe. Takim przykładem jest Alt + F7 który domyślnie pozwala na "złapanie aktywnego okienka" w celu jego przesunięcia w inne miejsce na ekranie. Niestety obsługa tego skrótu koliduje z domyślnym w Intellij do wyszukania referencji do klasy, metody, zmiennej...
Krótki przepis na usunięcie / zmianę ustawień systemowych:
a) wyszukujemy co korzysta ze skrótu:
gsettings list-recursively | grep \<Alt\>F7
widzimy dwie zdefiniowane akcje, pierwsza dla kombinacji Windows+Alt+F7, druga to akcja której szukamy:
org.gnome.mutter.wayland.keybindings switch-to-session-7 ['<Primary><Alt>F7']
org.gnome.desktop.wm.keybindings begin-move ['<Alt>F7']
b) zmieniamy ustawienie (w poniższym przykładzie usuwam działanie skrótu):
gsettings set org.gnome.desktop.wm.keybindings begin-move "['']"
Jeśli będziemy chcieli przywrócić funkjonalność:
gsettings reset org.gnome.desktop.wm.keybindings begin-move
Podziel się:

czwartek, 21 września 2017

poniedziałek, 7 sierpnia 2017

niedziela, 6 sierpnia 2017

środa, 2 sierpnia 2017

Useful git commands

Source: https://orga.cat/posts/most-useful-git-commands
Here there are some examples of git commands that I use often.
Not all commands written here are git commands, but all of them are related to git. Please refer to the documentation for more details.

Set your details

git config --global user.name "John Doe"
git config --global user.email "john@example.com"
Use --global to set the configuration for all projects. If git config is used without --global and run inside a project directory, the settings are set for the specific project.

Make git ignore file modes

cd project/
git config core.filemode false
This option is useful if the file permissions are not important to us, for example when we are on Windows.

See your settings

git config --list

Initialize a git repository for existing code

cd existing-project/
git init

Clone a remote repository

git clone https://github.com/user/repository.git
This creates a new directory with the name of the repository.

Clone a remote repository in the current directory

git clone https://github.com/user/repository.git .

Get help for a specific git command

git help clone

Update and merge your current branch with a remote

cd repository/
git pull origin master
Where origin is the remote repository, and master the remote branch.
If you don't want to merge your changes, use git fetch

View remote urls

git remote -v

Change origin url

git remote set-url origin http//github.com/repo.git

Add remote

git remote add remote-name https://github.com/user/repo.git

See non-staged (non-added) changes to existing files

git diff
Note that this does not track new files.

See staged, non-commited changes

git diff --cached

See differences between local changes and master

git diff origin/master
Note that origin/master is one local branch, a shorthand for refs/remotes/origin/master, which is the full name of the remote-tracking branch.

See differences between two commits

git diff COMMIT1_ID COMMIT2_ID

See the files changed between two commits

git diff --name-only COMMIT1_ID COMMIT2_ID

See the files changed in a specific commit

git diff-tree --no-commit-id --name-only -r COMMIT_ID
or
git show --pretty="format:" --name-only COMMIT_ID

See diff before push

git diff --cached origin/master

See details (log message, text diff) of a commit

git show COMMIT_ID

Check the status of the working tree (current branch, changed files...)

git status

Make some changes, commit them

git add changed_file.txt
git add folder-with-changed-files/
git commit -m "Commiting changes"

Rename/move and remove files

git rm removeme.txt tmp/crap.txt
git mv file_oldname.txt file_newname.txt
git commit -m "deleting 2 files, renaming 1"

Change message of last commit

git commit --amend -m "New commit message"

Push local commits to remote branch

git push origin master

See recent commit history

git log

See commit history for the last two commits

git log -2

See commit history for the last two commits, with diff

git log -p -2

See commit history printed in single lines

git log --pretty=oneline

Revert one commit, push it

git revert dd61ab21
git push origin master

Revert to the moment before one commit

# reset the index to the desired tree
git reset 56e05fced

# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}

git commit -m "Revert to 56e05fced"

# Update working copy to reflect the new commit
git reset --hard

Undo last commit, preserving local changes

git reset --soft HEAD~1

Undo last commit, without preserving local changes

git reset --hard HEAD~1

Undo last commit, preserving local changes in index

git reset --mixed HEAD~1
Or git reset HEAD~1
See also http://stackoverflow.com/q/927358/1391963

Undo non-pushed commits

git reset origin/master

Reset to remote state

git fetch origin
git reset --hard origin/master

See local branches

git branch

See all branches

git branch -a

Make some changes, create a patch

git diff > patch-issue-1.patch

Add a file and create a patch

git add newfile
git diff --staged > patch-issue-2.patch

Add a file, make some changes, and create a patch

git add newfile
git diff HEAD > patch-issue-2.patch

Make a patch for a commit

git format-patch COMMIT_ID

Make patches for the last two commits

git format-patch HEAD~2

Make patches for all non-pushed commits

git format-patch origin/master

Create patches that contain binary content

git format-patch --binary --full-index origin/master

Apply a patch

git apply -v patch-name.patch

Apply a patch created using format-patch

git am patch1.patch

Create a tag

git tag 7.x-1.3

Push a tag

git push origin 7.x-1.3

Create a branch

git checkout master
git branch new-branch-name
Here master is the starting point for the new branch. Note that with these 2 commands we don't move to the new branch, as we are still in master and we would need to run git checkout new-branch-name. The same can be achieved using one single command: git checkout -b new-branch-name

Create a branch from a previous commit

git branch branchname 
or using a symbolic reference (e.g. last commit):
git branch branchname HEAD~1
You can also use
git checkout -b branchname 

Checkout a branch

git checkout new-branch-name

See commit history for just the current branch

git cherry -v master
(master is the branch you want to compare)

Merge branch commits

git checkout master
git merge branch-name
Here we are merging all commits of branch-name to master.

Merge a branch without committing

git merge branch-name --no-commit --no-ff

See differences between the current state and a branch

git diff branch-name

See differences in a file, between the current state and a branch

git diff branch-name path/to/file

Delete a branch

git branch -d new-branch-name

Push the new branch

git push origin new-branch-name

Get all branches

git fetch origin

Get the git root directory

git rev-parse --show-toplevel

Remove from repository all locally deleted files

git rm $(git ls-files --deleted)

Delete all untracked files

git clean -f
Including directories:
git clean -f -d
Preventing sudden cardiac arrest:
git clean -n -f -d

Delete all files from a git repository that have already been deleted from disk:

git ls-files --deleted -z | xargs -0 git rm
Source (and alternatives): https://stackoverflow.com/a/5147119/1391963

Show total file size difference between two commits

Short answer: Git does not do that.
Long answer: See http://stackoverflow.com/a/10847242/1391963

Unstage (undo add) files:

git reset HEAD file.txt

See closest tag

git describe --tags `git rev-list --tags --max-count=1`
Source. See also git-describe.

Have git pull running every X seconds, with GNU Screen

screen
for((i=1;i<=10000;i+=1)); do sleep 30 && git pull; done
Use Ctrl+a Ctrl+d to detach the screen.

See previous git commands executed

history | grep git
or
grep '^git'  /root/.bash_history

See recently used branches (i.e. branches ordered by most recent commit)

git for-each-ref --sort=-committerdate refs/heads/ | head

Tar project files, excluding .git directory

cd ..
tar cJf project.tar.xz project/ --exclude-vcs

Tar all locally modified files

git diff --name-only | xargs tar -cf project.tar -T -

Look for conflicts in your current files

grep -H -r "<<<" *
grep -H -r ">>>" *
grep -H -r '^=======$' *
There's also git-grep.

Apply a patch not using git:

patch -p1 < file.patch
Podziel się:

środa, 21 czerwca 2017

Postgres - kopiowanie baz

Kopiowanie bazy z poziomu SQL:
CREATE DATABASE my_new_database TEMPLATE my_old_database;
Kopiowanie bazy z poziomu shell'a:
createdb -T my_old_database my_new_database;
Kopiowanie bazy za pomocą pg_dump i pg_restore:
pg_dump -Fc -f olddb.pgdump -d olddb && createdb newdb && pg_restore -d newdb olddb.pgdump
Podziel się:

środa, 17 maja 2017

poniedziałek, 8 maja 2017

Chleb żytni domowy


Przepis od Bosackiej...

Mieszamy dwie miarki mąki i ok 100 ml wody żeby otrzymać ciasto o konsystencji jak na gofry lub placki ziemniaczane. Codziennie zakwas dokarmiamy tą samą ilością mąki i wody przez kolejne 4 dni. Trzymamy w ciepłym miejscu w słoju przykrytym folią spożywczą albo ściereczką.
Chleb:
250 gram zakwasu
500 gram jasnej
200 gram razowej
400 ml wody
15 gram soli
Mieszamy w misce, przykrywamy folią i zostawiamy w misce na 4 godziny.
Przekładamy do foremek a foremki z ciastem wkładamy do worka foliowego na 0,5 - 2h. Ciasto powinnno wyrosnąć.
Pieczony 45-60 minut temp 220-240 stopni
Po upieczeniu wyrzucamy z foremek i zostawiamy na kilka godzin.
Podziel się:

środa, 3 maja 2017

czwartek, 6 kwietnia 2017

Montowanie zasobów samba jako system plików [cifs]

W systemach linux mamy pakiet, który pozwala na montowanie zasobów samba jako lokalnego systemu plików. Żeby móc z tego korzystać instalujemy pakiet cifs-utils.
Następnie w pliku /etc/fstab dodajemy wpis jak poniżej i tworzymy sobie lokalnie miejsce gdzie będzie montowany nasz zasób (u mnie to jest /home/network)

//HOST_IP_ADDRESS/directory /home/network cifs username=SAMBA_SHARE_USERNAME,password=SAMBA_SHARE_PASSWORD,uid=LOCAL_LINUX_USER,iocharset=utf8,file_mode=0777,dir_mode=0777,users 0 0

Potem sudo mount -a
I nasz zasób sieciowy powinien zostać zamontowany w /home/network
Podziel się:

sobota, 1 kwietnia 2017

Proces Java jako serwis [linux] z użyciem systemctl

Zaczynamy od utworzenia pliku startowego naszego serwisu w /etc/systemd/system
[Unit]
Description=Java Service

[Service]
User=LINUX_USER
WorkingDirectory=/data 
ExecStart=/usr/bin/java -Xmx256m -jar application.jar
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target
Przeładowujemy konfiguracje serwisów:
systemctl daemon-reload
I włączamy serwis:
systemctl enable javaservice.service
Kilka pomocniczych poleceń:
systemctl start javaservice
systemctl stop javaservice
systemctl restart javaservice
systemctl status javaservice

Podziel się:

środa, 22 marca 2017

czwartek, 16 marca 2017

KIANO Slimstick i Linux [Ubuntu]

Kiano Slimstick to mini komputer, który możemy podłączyć bezpośrednio do wejscia HDMI w monitorze lub telewizorze. Standardowo w polskiej dystrybucji dostarczany jest z systemem Windows 10. Mamy jednak możliwość zmiany systemu operacyjnego na linux.

Obecnie są przygotowane różnych wariacji Ubuntu, Chromium OS i Android.
Obrazy możemy pobrać tutaj. Strona zawiera także szczegółowe instrukcje instalacji.

Ja na swoim zainstalowałem Xubuntu 16.04.2 (środowisko graficzne XFCE) zastępując całkowicie system Windows. Wszystkie podzespoły działają bez problemu, Zauważalna zdecydowanie poprawa w działaniu wifi. Krótka instrukcja instalacji:

  1. Pobieramy obraz ISO interesującej nas wersji.
  2. Pobieramy program Rufus służący do nagrywania obrazu ISO na pendrive'a.
  3. Podłączamy pendrive z nagranym obrazem do naszego Kiano, startujemy i przytrzymujemy F7
  4. Wybieramy start z pendrive'a zamiast Windows Boot Manager'a
  5. Po załadowaniu Ubuntu sprawdzamy czy wszystko działa i możemy instalować.
Zainteresowanym instalacją Ubuntu obok Windows odsyłam do wspomnianej strony.
Podziel się: