/** * Instances CANNOT use private and protected members * Children CAN inherit only public and protected members */ class MyClass { public $name = 'John'; protected $username = 'JohnT23'; private $password = 'secret'; function printAll() { echo "From class MyClass:"; echo $this->name." "; echo $this->username." "; echo $this->password." "; } } $obj = new MyClass(); echo "From Instance \$obj:".$obj->name."\n"; //Works //echo $obj->username; // Fatal Error //echo $obj->password; // Fatal Error $obj->printAll(); echo"\n<br>"; class MyClass2 extends MyClass { // We can re-declare/access the public and protected method // but not private ones function printAll() { echo "From class MyClass2:"; echo $this->name." "; echo $this->username." "; // Children cannot access private member of parent // echo $this->password; // Error } } $obj2 = new MyClass2(); echo "<br> From Instance \$obj2:".$obj2->name; // Works //echo $obj->username; // Fatal Error //echo $obj->password; // Fatal Error $obj2->printAll();
Monday, March 3, 2014
OOP Basics
Sunday, February 23, 2014
Testing File Permission for file upload and database connectivity
On a freshly installed Linux server you need to test file permission and database connectivity.
Here are some scripts that can help you with that:
Here are some scripts that can help you with that:
Wednesday, February 12, 2014
Git protocol on server and client side
This is an advanced tutorial for experienced users that are familiar with git, SSH protocols and shell scripts.
On server side
Do not close the terminal on server.
On server side
[user@test_server ~]$ git daemon --base-path=/var/www/html --reuseaddr --export-all --verbose --enable=receive-pack
Do not close the terminal on server.
--base-path=/var/www/html is path to your repository.Saturday, January 18, 2014
Two Way Encryption
Two way encryption on PHP works with mcrypt extension enabled.
Here's a simple snippet that uses password and generates different encryption string every time you reload.
Here's a simple snippet that uses password and generates different encryption string every time you reload.
<?php $string = "This is a string to be encrypted"; $key = "This is a key"; // Encryption Algorithm $alg = MCRYPT_TWO_FISH; // Create the initialization vector for added security $iv = mcrypt_create_iv(mcrypt_get_iv_size($alg, MCRYPT_MODE_ECB), MCRYPT_RAND); // Output original string print "Original string: $string <p>"; // Encrypt $string $encrypted_string = mcrypt_encrypt($alg, $key, $string, MCRYPT_MODE_CBC, $iv); // Convert to hexadecimal and output to browser print "Encrypted string: ".bin2hex($encrypted_string)."<p>"; $decrypted_string = mcrypt_decrypt($alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv); print "Decrypted string: $decrypted_string"; ?>A short video how code works
Saturday, January 11, 2014
Two aliases for the same MySQL table
Here's how to establish database relationships between connected entities. In this example we'll use a highways map. The final query will show city names and highway that connects them in result set rows.
Map of highways:
Map of highways:
| Connections between cities |
Thursday, December 19, 2013
Git most used features
Cache credentials if you need to enter credentials only once and they are cached for 900 seconds
git config credential.helper 'cache --timeout=3000'Create branch from an existing branch and switch to it
git checkout -b new_branch developCreate branch from commit and switch to it
git checkout -b new_branch d9410d98f69d08Diff between local and remote branch
git fetch git difftool origin/develop develop # to refresh develop branch git pullDelete branches that don't exist on remote repo - sync remote and local repo
# git remote prune origin * [pruned] origin/branch_name # git branch -d branch_name # manually remove orphancomparing files in two revisions
# this will launch diff tool for one file in two revisions $ git difftool 344c f8cc proba.txt # this will launch diff tool for one file in commit and working directory $ git difftool a9a5f2a ./component.ts # Usage of difftool for comparing all files in two revisions git difftool 8c6a dd6bCompare current commit with previous one
git difftool HEAD..HEAD~1Put in zip archive files from single commit
git archive -o latest.zip HEADMy favorite format for log
git log --pretty=format:"%C(#cd9a00)%h %C(#0080ff) <%an> %C(#17b062)(%cr) %d %C(#c0d6de)%s"remove ajax.php from version control but not from file system
git rm --cached ajax.php git commit -m 'removed ajax.php from git'put file from past commit to index and view diff.
git checkout 42cf1ad -- package.json git difftool --cachedSearch every branch in Git Repository and find commit containing messageb or regex search fin.*me in specified time range and print hash, line number and lines around matching line.
# in PowerShell and Linux git grep -in -C 1 messageb $(git rev-list --all) git grep -in -C 1 fin.*me $(git rev-list --all --since="2021-05-10" --before="2021-05-26")another useful when looking for source code in all branches
# search in all files in all branches
# only Linux
git rev-list --all | (
while read revision; do
git grep -F 'yourWord' $revision
done
)
to find branch with SHA
$ git branch -a --contains 08d70aa131ded0ca84f9d31b7 newmainsearch all commit messages in all branches
git log --all --oneline | grep "yourWord"How single file changed in past by time and between commits
git log --follow -p --since="2 hours ago" -- README.md git log --follow -p HEAD~3..HEAD -- README.mdList commits for my_branch since it's creation
git log --pretty=format:"%C(#cd9a00)%h %C(#0080ff) <%an> %C(#17b062)(%cr) %d %C(#c0d6de)%s" master..my_branchSolve conflict, merge and refresh feature branch from master
git checkout -b my-branch # create new branch from master # modify line, commit & push # in GitLab modify same line add commit on master # create merge request, try to merge it - it fails git checkout master git pull # refresh local copy git checkout my-branch git merge master # merge, commit & push # merge my-branch into master in GitLab using merge requestInstall diff and merge tool for Windows: 1.Install KDiff3 2.Place this in .gitconfig file
[difftool "kdiff3"]
path = "c:/Program Files/KDiff3/kdiff3.exe"
trustExitCode = false
[difftool]
prompt = false
[diff]
tool = kdiff3
[mergetool "kdiff3"]
path = "c:/Program Files/KDiff3/kdiff3.exe"
trustExitCode = false
[mergetool]
keepBackup = false
[merge]
tool = kdiff3
Labels:
branch,
branch as commit,
branch from commit,
commit,
compare,
difftool,
Git,
HEAD,
KDiff3,
linux,
Meld,
mergetool,
remote repo,
revert,
version control,
Windows,
zip archive
Location:
New York, NY, USA
Saturday, December 7, 2013
jQuery animate and queue
Simple HTML with two div elements that shows jQuery's animate and queue effects.
Yellow paragraph simultaneously changes height and width.
Grey paragraph first changes height and then width.
Yellow paragraph simultaneously changes height and width.
Grey paragraph first changes height and then width.
Subscribe to:
Posts (Atom)