May 31, 2018

convert between GPT and MBR partitions using diskpart

In Windows command (cmd), run "diskpart" as administrator.


In the "diskpart" command,
to check the type of partition,
        list disk

to select a disk,
        select disk #   (#: disk number)

to convert,
        convert MBR  (convert to MBR partition)
        or
        convert GPT  (convert to GPT partition)

to create a volume,
        create partition primary (size=???)  (if size is missing, the whole size is used as a volume)

to format the created volume,
        (select partition #)
        (active)   (this is for MBR partition)
        format fs=FAT32 (quick)



Jan 1, 2018

[Python] an example of I/O, file I/O

a = float(input('enter any number: '))
print('%f * %f = %f\n' % (a, a, a*a))


a,b = input('enter any two numbers: ').split()  # split(): two numbers with space in between;  split(','): two numbers with , in between
print('%f * %f = %f\n' % (float(a), float(b), float(a)*float(b)))


now = time.localtime()
filename = "log_%02d%02d%02d_%02d:%02d:%02d.txt" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
f = open(filename, 'w')  # r: read-only,  r+: read and write, w: write,  a: append
f.write('abcdefgh')
f.close()


g = open('t.txt', 'r')
line = g.readline()
while line:
 print (line, end='\n')
 line = g.readline()
g.close()


h = open('t.txt', 'r')
lines = h.readlines()
for line in lines:
 print(line*2, end=' ')
h.close()


Result------------------------------------------
enter any number: 1.000000 * 1.000000 = 1.000000

enter any two numbers: 1.000000 * 2.000000 = 2.000000

abcdefgh
abcdefghabcdefgh 

[Python] an example of function, module

def add3(a,b,c):  # define a function
 return(a+b+c)
print(add3(1,2,3),"\n")
 
 
def add(*vary):
 for i in vary:
  print(i)
add(1,2,3,4)

 

# if the above function is saved in add.py and you'd like to use it as a module,
#  import add
#  add.add3(1,3,4)
#
# if you'd like to directly use all functions in add.py,
#  from add import *
#  add3(2,4,5)

[Python] an example of if, while, for

a=500
if (500<a<600):
 print("a>500")
elif (a==500) or (a==400):
 print("a=500")
else:
 print("a<500")
 

while a>450:
 print(a, a-1, a-2, a-3, a-4)
 a=a-5
print()
 

while a>400:
 print(a, a-1, a-2, a-3, a-4)
 a=a-5
 if a==415: break
print()
 
 
while a>300:
 a=a-5
 if a%10==0: continue
 print(a, a-1, a-2, a-3, a-4)
print()


x=[1,2,3,4,5]
for i in x:
 print(i/2)
print()
 

for i in range(5):
 for j in range(2,5):
  print(i,j)
print()
 
for i in range(len(x)):
 print(i)
print()

Result---------------------------------------------
a=500
500 499 498 497 496
495 494 493 492 491
490 489 488 487 486
485 484 483 482 481
480 479 478 477 476
475 474 473 472 471
470 469 468 467 466
465 464 463 462 461
460 459 458 457 456
455 454 453 452 451

450 449 448 447 446
445 444 443 442 441
440 439 438 437 436
435 434 433 432 431
430 429 428 427 426
425 424 423 422 421
420 419 418 417 416

405 404 403 402 401
395 394 393 392 391
385 384 383 382 381
375 374 373 372 371
365 364 363 362 361
355 354 353 352 351
345 344 343 342 341
335 334 333 332 331
325 324 323 322 321
315 314 313 312 311
305 304 303 302 301

0.5
1.0
1.5
2.0
2.5

0 2
0 3
0 4
1 2
1 3
1 4
2 2
2 3
2 4
3 2
3 3
3 4
4 2
4 3
4 4

0
1
2
3
4

[Python] an example of print-formatting, list-handling

a=3.141592
b=1.23
c=89
print(format(a, '.2f'), format(a, '10.2f'))
print('{0:5f}'.format(a), '{0:5f}'.format(b), '{0:5d}'.format(c))
print('{0:>8f}'.format(a), '{0:>8f}'.format(b), '{0:>8d}'.format(c))
print('{0:<8f}'.format(a), '{0:<8f}'.format(b), '{0:<8d}'.format(c))
print()

d="AbCdbeFgbhcC"
print(d[1:3], d[0], d[1:], d[:5])
print(d.upper(), d.lower())
print(d[1:3].upper(), d[:5].lower())
print(d.find('de'))
print(d.find('de',3))
print(d.find('de',4))
print(d.find('the'))
print(d.count('c'))
print(d.replace('C','Z'))
print(d.split('b'))

e=d.split('b')
f="="
print(f.join(e))
print()

e.append('ddddd')
e.append(3)
print(e)
e.insert(2,'xx')
print(e)
e.extend([1,1,2,'vv'])
print(e)
print(e.index(1), e.index('xx'))
print(e.count(1))
e.pop(0)
print(e)
e.pop()
print(e)
e.remove('xx')
print(e)
print()

g=[1,3,4,2,0]
g.sort()
print(g)
g.sort(reverse=True)
print(g)

h=['x','aa','b','yy','c','d','e']
h.sort()
print(h)
h.reverse()
print(h)


Result--------------------------------------------------------
3.14       3.14
3.141592 1.230000    89
3.141592 1.230000       89
3.141592 1.230000 89      

bC A bCdbeFgbhcC AbCdb
ABCDBEFGBHCC abcdbefgbhcc
BC abcdb
-1
-1
-1
-1
1
AbZdbeFgbhcZ
['A', 'Cd', 'eFg', 'hcC']
A=Cd=eFg=hcC

['A', 'Cd', 'eFg', 'hcC', 'ddddd', 3]
['A', 'Cd', 'xx', 'eFg', 'hcC', 'ddddd', 3]
['A', 'Cd', 'xx', 'eFg', 'hcC', 'ddddd', 3, 1, 1, 2, 'vv']
7 2
2
['Cd', 'xx', 'eFg', 'hcC', 'ddddd', 3, 1, 1, 2, 'vv']
['Cd', 'xx', 'eFg', 'hcC', 'ddddd', 3, 1, 1, 2]
['Cd', 'eFg', 'hcC', 'ddddd', 3, 1, 1, 2]

[0, 1, 2, 3, 4]
[4, 3, 2, 1, 0]
['aa', 'b', 'c', 'd', 'e', 'x', 'yy']
['yy', 'x', 'e', 'd', 'c', 'b', 'aa']


Nov 20, 2017

[C/Cpp] How to include an external function in a C code

If you'd like to use an external function of add.c in main.c, you need to import the function in main.c.
Then, compile main.c with having add.c in same folder.


main.c
#include <stdio.h>
#include "add.c"
 
extern int add(int x, int y);
extern int sum;
 
 
void main(void)
{
 int a=2, b=5;
 
 sum = add(a,b);
 printf("%d\n", sum);
}


add.c
#include <stdio.h>
 
int add(int x, int y);
int sum=0;
 
int add(int x, int y)
{
 sum = x+y;
 return sum;
}


Oct 13, 2017

How to create a txt file containing a list of all files and sub-folders

In a cmd window,
"dir /b" will list all files and sub-folders in a folder.
To make a list file (list.txt) containing all information that comes after the "dir /b" command,
"dir /b < list.txt"

If you want to list files only,
"dir /a:-d /o:n /b  < list.txt"

If you want to list sub-folders only,
"dir /a:d /o:n /b  < list.txt"


"/o:n" results in an alphabetically sorted list

Reference:
http://blog.daum.net/graphixxx/13631801