During implementation of DistTest I faced with necessity of building a lot of different linux kernel versions. As a first solution I chose downloading archives from kernel.org for each used version. But I soon realized that about 1000 versions of sources with size 0.5-1GB each would consume a lot of disk space. It’s also impossible to build kernel with exact commit precision using this approach.
Set of base versions with corresponding patches can save disk space, but uses a lot of random I/O during applying patches, so it’s slow on HDD and consume finite rewrite resource of SSD. Temporary nature of sources leads to conclusion “use tmpfs”. But aufs offers much less RAM consuming method – store in RAM only diffs.
Category Archives: programming
git linuxSpace efficient source code storage
23.03.2016 – 23:28
Selfmade dyndns
10.01.2015 – 02:38
Dyn.com stopped providing free dyndns hosting some time ago. It were sad news.
However most necessary functionality can be implemented in 70 lines of code.
To dynamically update dns records we must find a way to:
- get current ip
- update DNS record
- schedule script for execution
1. Getting current ip address
Many ISP use NAT for security and money saving reasons. Also NAS used in routers. So, to get your IP address you need to ask your IP address from service located outside your network.
For example internet.yandex.ru web page ask resource http://ipv4.internet.yandex.ru/api/v0/ip to determine IP address. So, let’s use it.
1 2 3 4 5 6 |
use constant IP_API_URI => 'http://ipv4.internet.yandex.ru/api/v0/ip'; sub get_ip($) { my ($ua) = @_; my $response = get($ua, IP_API_URI); return substr $response, 1, length($response)-2; #clean out quotes } |
2. Updating DNS record
Yandex provide API for DNS records management for domains parked in yandex. API reference should be located here but link is currently broken :-(. UPD: API reference.
In two words you should send POST request with token in header and data in request’s body to https://pddimp.yandex.ru/api2/admin/dns/edit url.
It should looks like following snippet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
use constant DNS_API_URI_PREFIX => 'https://pddimp.yandex.ru/api2/admin/dns/'; sub post($$$%){ my ($ua, $url, $data, %headers) = @_; my $req = HTTP::Request->new(POST => $url); $req->header(%headers) if keys %headers; $req->content_type('application/x-www-form-urlencoded'); $req->content($data); my $res = $ua->request($req); return $res->content if $res->is_success; return undef; } sub set_domain_ip($$$$$$){ my ($ua, $token, $domain, $subdomain, $record_id , $ip) = @_; return decode_json post($ua, DNS_API_URI_PREFIX."edit", "domain=$domain&record_id=$record_id&subdomain=$subdomain&ttl=14400&content=$ip", PddToken => $token); } |
3. Scheduling dns records updating
Use the cron, Luke :-) I mean that adding following line to cronjobs would be a simplies way to schedule updating of our dns records:
1 |
* * * * * ( token=123 /home/user/yandex_dns.pl --domain=domain.com --subdomain=subdomain ) |
That’s all. Complete script on github.
Buzz words collection
16.07.2014 – 21:41
My collection of programmers buzz words. I think it will be useful for beginner programmers and Software Engineering students. Will be actively replenished.

Principles
- Defensive programming
- KISS – Keep it simple, stupid
- DRY – Don’t repeat yourself
- YAGNI – You Ain’t Gonna Need It
- ACID – Atomicity Consistency Isolation Durability
- Inversion of control
- Uniform Access Principle
- Law of Demeter
- SOA – Service-oriented architecture
- GRASP – General Responsibility Assignment Software Patterns
- SOLID
- Single responsibility principle
- Open/closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle
Some weekend’s madness
19.08.2013 – 00:18
I’ve just tried to follow intellij idea’s manual and develop some useless plugin. And now my plugin can display “Hello world” program on perl.
You also can view this madness on github.
UPD1. Some new lexical constructions support added.
Link assembly and c
01.06.2013 – 12:53
I using nasm to generate object code from assembly source. 3 application required to compile executable:
– nasm
– gcc from gcc-
– ld from binutils package
*package names in ubuntu distribution
To install this packages run following command:
1 |
sudo apt-get install nasm binutils gcc-4.7-base |
Files contents:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
global func section .text func: push rbp mov rbp, rsp mov rax, 1 ; sys_write mov rdi, 1 ; stdout mov rsi, message ; message address mov rdx, length ; message string length syscall pop rbp ret section .data message: db 'Hello, world!',0x0A ; message and newline length: equ $-message ; NASM definition pseudo-instruction |
1 2 3 4 5 6 |
void func(); //may be extern void func(); is more true way int main(){ func(); return 0; } |
1 2 3 |
nasm -f elf64 func.asm gcc -c use_asm.c gcc use_asm.o func.o -o use_asm |
And finaly:
1 2 |
$ ./use_asm Hello, world! |
Precision of calculation with floating point numbers
25.05.2013 – 14:26
I found some curiosity issues during finding optimal tool for compilation our program. Results of computations be different for different tools and different optimisation flags.
For investigating this issue I write simple code(full sources on github):
1 2 3 4 5 |
int i; long double res; for(i=0;i<100000000;i++){ res += cos(i); } |
In this small test program I can’t reproduce different results for different flags. But 5 different results for so similar programs is enough to demonstrate discovered effect.
Source code and tool | Result | Computation time, s |
Assembler | 1.53436944477410652787 | 3.81 |
gcc long | 1.53436944477462278158 | 4.4 |
gcc double | 1.53436944477389380914 | 4.4 |
icc long | 1.53436944477397574360 | 6.88 |
icc double | 1.53436944477334602510 | 1.50 |
p.s. also I found that manually written assembly code 15% faster than code on C in spite of using “-O2” optimisation flag.
Suffering Oriented Programming
24.10.2012 – 20:12
Remote SVN backup with svnsync
07.09.2012 – 01:50
Create local svn repository with name “my_local_repo”
1 |
$ svnadmin create my_local_repo |
prepare local repo
1 2 |
$ echo "#!/bin/sh" > hooks/pre-revprop-change $ chmod 755 hooks/pre-revprop-change |
initialize local copy
1 |
$ svnsync init file:///path/to/my_local_repo http://from.server/from_repo |
first run must be interactive to input and save your login and password
1 |
svnsync sync file:///path/to/my_local_repo |
write script to run it in cron
backup_svn_script.sh:
1 2 3 |
#!/bin/bash svnsync --non-interactive sync file:///path/to/my_local_repo tar -C /path/to/ -czf /path/to/backup/$(date +"svn_%Y_%m_%d_%H_%M_%S").tar.gz my_local_repo |
it produce files like “svn_2012_09_07_01_34_01.tar.gz” in your backup directory
Now you can add task to cron. Execute:
1 |
$ crontab -e |
and add following line to run backup at 4:00 (4 a.m.) every day
1 |
0 4 * * * /path/to/backup_svn_script.sh |
This method is not disk space efficient, but very simple.
Sources:
using svnsync
installing subversion server in ubuntu