Skip to main content

Posts

Showing posts from 2019

Swift by Sundell

Re note some refactoring techniques and concepts Bad Smells in code: Duplicate, long method, large class, long parameter list, divergent change (?), shotgun surgery Feature envy, Data clumps, lazy class, middle man, message chains, ... Techniques: Composing methods, Moving features between objects Organizing data Simplifying conditional expressions Making method calls simpler Dealing with generalization Some interesting material from Sundell for some ideas, technique on what is bad code and how to refactor it. Lightweight API design in Swift https://www.swiftbysundell.com/articles/lightweight-api-design-in-swift/     Often when we design how our various types and functions will interact with each other, we have to find some form of balance between power and ease of use. Make things too simple, and they might not be flexible enough to enable our features to continuously evolve — but on the other hand, too much complexity often leads to frustration, misunderstandings, a

Swift optimize compiling time

Compiling development have pain in the ass issues: compiling time. With many mainly Script developer like me, we familiar with edit => refresh => testing => done. But with compiling language like iOS Swift or Android Java/Kotlin, even single bit of change to source code require rebuild (In my knowledge). And it make newbie more stress, panic since you are new and have to make small change step by step to trial and error to see what take effect... I mean newbie have to make more build Time compiling >=2 minutes (120s)  Slowest ~5 minutes - ~500 file source => 50-75s compile - assets ~500files ~7s - XIB some take huge time to compile (15-23s); randomly slow each build ie. TagUser..xib some time slow, so it hard to know exactly which xib slow. - The more file, module included, the more tangled, required messing, So it hard to comment out/ exclude one file. And then total compile time spike up. 1. Almost all Pods libraries already removed: - Twitter - Facebook

Refactoring, Eloquent load vs with etc.

https://martinfowler.com/bliki/RefactoringMalapropism.html https://martinfowler.com/tags/refactoring.html https://stackoverflow.com/questions/26005994/laravel-with-method-versus-load-method Damn dump dd Laravel     "review" => array:5 [       0 => array:10 [ …10]       1 => array:10 [ …10]       2 => array:10 [ …10]       3 => array:10 [ …10]       4 => array:10 [ …10]     ] It seem clever to wrapping long array to look like above. But when I search for a missing record ID, it not show here. So I have to debug to figure out why it is missing in the first dump but show on latter result. https://www.owasp.org/index.php/SQL_Injection_Bypassing_WAF https://github.com/Intervention/image https://github.com/itsgoingd/clockwork composer pheanstalk https://duo.com/labs/research/apple-t2-xpc https://stackoverflow.com/questions/29684111/how-to-compare-two-carbon-timestamps/29684354 https://stackoverflow.com/questions/6182356/what-is-2c-in-a-url

LAMP / LEMP development note 30-Sept-2019

Count Apache's (httpd) concurrent connections https://www.2daygeek.com/linux-check-apache-concurrent-connections-netstat-ss-command/ $htpasswd -b -c ~/temp/password admin test101 https://www.networkworld.com/article/2874387/mission-impossible-memorizing-ipv6-addresses.html  Chrome & Firfox Dark mode seem cool. https://stackoverflow.com/questions/19646567/is-there-a-way-to-get-client-connections-count-in-aws-elb ELB actually runs on EC2 (?), which would only make sense, and would explain why it can't scale up extremely rapidly in response to traffic spikes. YOU CAN’T PROTECT WHAT YOU CAN’T SEE https://medium.com/tenable-techblog/lessons-from-aws-nlb-timeouts-5028a8f65dda https://stackoverflow.com/questions/6375654/how-to-add-date-string-to-each-line-of-a-continuously-written-log-file Difference between ESTABLISHED and LISTENING https://askubuntu.com/questions/854354/difference-between-established-and-listening https://users.cs.northwestern.edu/~agupta/cs

Simulate Fail2ban on Apache request spam with mod_evasive limitipconn ...

https://en.wikipedia.org/wiki/Manchu_alphabet https://en.wikipedia.org/wiki/Sweet_potato https://en.wikipedia.org/wiki/New_World_crops https://www.mdpi.com/journal/energies http://www.cired.net/publications/cired2007/pdfs/CIRED2007_0342_paper.pdf https://www.davidpashley.com/articles/writing-robust-shell-scripts/ trap command https://en.wikipedia.org/wiki/Race_condition https://unix.stackexchange.com/questions/172541/why-does-exit-1-not-exit-the-script exit 1 not work it seem { } brace bound fixed it. cat access_log | cut -d ' ' -f 1 > ip1 sort -n -t. -k1,1 -k2,2 -k3,3 -k4,4 | uniq -c | sort -n -r -s https://unix.stackexchange.com/questions/246104/unix-count-unique-ip-addresses-sort-them-by-most-frequent-and-also-sort-them https://stackoverflow.com/questions/20164696/how-to-block-spam-and-spam-bots-for-good-with-htaccess  Code: ------------------------------------------------------------------- #Block Spam Bots and Spam on your website #Block proxies

Notes on LAMP/LAPP Sept 19

https://en.wikipedia.org/wiki/B%C3%A9zier_curve https://www.quora.com/Can-virus-and-bacteria-survive-in-salt-water https://blog.goodaudience.com/bitcoin-vs-banks-78b7410fbe9 borrow metaphor from progmng language => are there some "reserve words" (keyword) in some language ? So master these will maximum (or at least optimum) to usage Sometime the different between prod and dev env reveal some interesting case study. ie. situation when prod sold table only have few records vs dev (not cleaned ?) have about half millions records. So query that designed to overcome bottleneck on join/not in ... on DEV env become not necessary and vice verse. On the other hand, we should keep DEV env implementation in case Live data not cleaned or sometime/somehow become larger, so the already logic could handled situation. Implement that prevent future table size is cool. We often ignore this when first work proposal.In the often used App/FW like WP we can easily grab best practice

PHP CSV pagination (chunk), Postgresql

https://github.com/symfony/http-foundation/blob/master/File/File.php https://stackoverflow.com/questions/39972653/laravel-chunk-method-using-eloquent ./src/Illuminate/Database/Concerns/BuildsQueries.php@chunk() https://medium.com/@barryvdh/streaming-large-csv-files-with-laravel-chunked-queries-4158e484a5a2 https://stackoverflow.com/questions/3705318/simple-php-pagination-script Use virtual mc as old version system config to figure out what feature worth, case study: multi threaded in psql 9.6+ Kl idea on build some computing powerhouse lab. For example running multiple server with software both old and new to experiment and performance compare... Scale up to a lab for education & training is cool. https://en.wikipedia.org/wiki/Kunming%E2%80%93Singapore_railway https://stackoverflow.com/jobs/293378/devops-engineer-automate-and-scale-securityscorecard Job description The Opportunity SecurityScorecard is hiring an Ops Engineer to bridge the gap between our global deve

FTP FTPS SFTP Concept, install, config and usage with certificate file

Proftpd  32 # To cause every FTP user to be "jailed" (chrooted) into their home  33 # directory, uncomment this line.  34 #DefaultRoot ~ https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol Compared to the SCP protocol, which only allows file transfers, the SFTP protocol allows for a range of operations on remote files which make it more like a remote file system protocol. An SFTP client's extra capabilities include resuming interrupted transfers, directory listings, and remote file removal. SFTP is not FTP run over SSH, but rather a new protocol designed from the ground up by the IETF SECSH working group. https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13 https://en.wikipedia.org/wiki/Internet_Engineering_Task_Force https://en.wikipedia.org/wiki/Syslog-ng https://en.wikipedia.org/wiki/File_Transfer_Protocol 2yz – Success reply 4yz or 5yz – Failure reply 1yz or 3yz – Error or Incomplete reply The second digit defines the

PHP smarty UTF-8 German ẞẞẞ

https://www.php.net/manual/en/function.file.php It return an array contain each lines. a hah https://www.owasp.org/index.php/Testing_for_Local_File_Inclusion https://qiita.com/nito128/items/b78d44c414fbb918ec10 Strauß pflücken können, wie er ihm gefällt Wir müssen wissen — wir werden wissen 欄で日本 Strauß pflücken können, wie er ihm gefällt 欄で日本 jürgen elmsheuser Wir müssen wissen — wir werden wissen 欄で日本文字化けしてしまう ä ö ü ß Ö Ä Ü ẞ ẞ ẞ ẞ ẞ ẞ ẞ 欄で日 éàèùâêîôûëïüÿçœæÉÀÈÙÂÊÎÔÛËÏܟnjƠ https://stackoverflow.com/questions/7764176/how-to-copy-from-current-position-to-the-end-of-line-in-vi https://en.wikipedia.org/wiki/Hindi exploit some oop from Smarty.class.php to see how an class constructed. https://superuser.com/questions/333856/ftp-authentication-with-public-key |replace:"\xe1\xba\x9e":"\xc3\x9f"

Note on custom build legacy php, apache CentOS

https://stackoverflow.com/questions/979453/how-can-i-use-aliased-commands-with-xargs/979504 find -name \*bar\* | xargs bash -ic gi foo It seem use bash function is easier. I remember that I've create some function like this before, it look like this: #DIRECTORY=$1 FILETYPE = $1 KEYWORD = $2 find . -name "*.FILETYPE" | xargs grep -rni KEYWORD $1 ... https://serverfault.com/questions/421161/how-to-configure-vsftpd-to-work-with-passive-mode https://www.yanxurui.cc/posts/server/2017-03-21-NGINX-as-a-file-server/ https://serverfault.com/questions/807074/enable-password-login-for-sftp-while-keeping-authentication-by-ssh-keys ... PasswordAuthentication no ... Match user drupalsftp     PasswordAuthentication yes PasswordAuthentication no ... Match user drupalsftp address 10.1.2.3/32     PasswordAuthentication yes     # also since we want only sftp     ForceCommand internal-sftp Err Traceback (most recent call last):   File "/usr/bin/yum

Notes on regex sed, bash DOM html, meta tag

Using bash tool sed, awk, grep, vim ... to edit multiple file. Case study DOM tag <html DOCTYPE, meta, charset... https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string Sed cheatsheet https://gist.github.com/asenchi/2291903 HTML meta tags (recommend way ?) https://www.quackit.com/html_5/tags/html_meta_tag.cfm Example <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml " xml:lang="ja" lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html" charset="EUC-JP" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta name="description" content="content here"

Notes PSQL, Apache X-Forwarded-Proto ...

 PSQL search column by name; select t.table_schema,        t.table_name from information_schema.tables t inner join information_schema.columns c on c.table_name = t.table_name                                 and c.table_schema = t.table_schema where c.column_name = 'last_name'       and t.table_schema not in ('information_schema', 'pg_catalog')       and t.table_type = 'BASE TABLE' order by t.table_schema; oh detail ab flow request HTTP to HTTPS only To understand X-Forwarded-Proto you have to understand the normal flow of communication when a client makes an HTTP request to a HTTPS-only resource. https://community.pivotal.io/s/article/Purpose-of-the-X-Forwarded-Proto-HTTP-Header   https://stackoverflow.com/questions/2987433/how-to-import-csv-file-data-into-a-postgresql-table https://stackoverflow.com/questions/26620670/apache-httpx-forwarded-proto-in-htaccess-is-causing-redirect-loop-in-dev-envir  It seem redirect first permanent br