Skip to content

Instantly share code, notes, and snippets.

View unknowntpo's full-sized avatar

Eric Chang unknowntpo

  • Taiwan
View GitHub Profile
@unknowntpo
unknowntpo / strcpy.c
Created February 18, 2020 05:57
Most beautiful strcpy.c
/* copy t to s ; pointer version 1 */
void strcpy(char *s, char *t) {
while (*s++ = *t++)
;
}
/* copy t to s ; pointer version 2 */
void strcpy(char *s, char *t) {
while (*s++ = *t++)
;
}
/* copy t to s ; pointer version 1 */
void strcpy(char *s, char *t) {
@unknowntpo
unknowntpo / rect.c
Last active March 11, 2020 00:07
Follow the practice in K&R 6.2 Structure and Functions, to implement a program that can check whether a point is in rectangle or not.
/*
* @ File name: rect.c
* @ Author: unknowntpo at 2020.2.24 (Mon)
* @ Title: Check whether a point is in rectangle or not.
* @ Short description:
* Make two point to form a rectangle called 'screen',
* and count the middle point.
* then, use ptinrect(middle, screen) function to check that
* middle point is in the rectangle.
* @ K&R_6.2: structures and functions
int adder(int a, int b)
{
int sum = a ^ b;
int carry = a & b;
if (carry == 0)
return sum;
return adder(sum, carry << 1);
}
"" syntax on
set number
" set the indent consistant to 4
set tabstop=8
set softtabstop=0 expandtab shiftwidth=4 smarttab
set laststatus=2
set clipboard+=unnamed
set hlsearch
" Folding
@unknowntpo
unknowntpo / db_version_control.insert_new_data.md
Last active September 2, 2022 00:35
db_version_control.data_version_1
id c0 c1 username version is_deleted
1 old0 old1 Eric 1 f
2 old2 old2 Eric 1 f
@unknowntpo
unknowntpo / data_table.sql
Created September 2, 2022 00:30
db_version_control.create_table
create table data (
id serial,
c0 text,
c1 text,
username text,
version integer,
is_deleted boolean
);
@unknowntpo
unknowntpo / data_table.sql
Created September 2, 2022 00:33
db_version_control.create_table
create table data (
id serial,
c0 text,
c1 text,
username text,
version integer,
is_deleted boolean
);
@unknowntpo
unknowntpo / create_temp_table.sql
Created September 2, 2022 00:43
db_version_control.insert_new_data_to_temp_table
CREATE TABLE temp (LIKE data INCLUDING ALL);
insert into temp (c0, c1, username, version, is_deleted) values
('modified', 'old1', 'Eric', 2, false),
('old2', 'old2', 'Eric', 2, false),
('new0', 'new1', 'Kevin', 2, false);
select * from temp;
@unknowntpo
unknowntpo / compare.sql
Created September 2, 2022 00:46
db_version_control.comparison_with_full_outer_join
select
temp.id as temp_id,
temp.c0 as temp_c0,
temp.c1 as temp_c1,
temp.username as temp_username,
temp.version as temp_version,
data.id as data_id,
data.c0 as data_c0,
data.c1 as data_c1,
data.version as data_version