Wednesday, May 4, 2016

Patterns, Anti-Patterns and Re-factoring

PHP Refactoring Book:
http://bookzz.org/book/721219/b30025

Design Pattern Basics w/ Examples:
http://www.fluffycat.com/PHP-Design-Patterns/

SourceMaking
(bible of design patterns,anti-patterns and refactoring info)
https://sourcemaking.com/

Thursday, March 31, 2016

VIM Tabs

Setting Tabstops


Use space characters in place of tabs:
:set expandtab


Set tab size to equal 4 spaces:
:set tabstop=4

:set shiftwidth=4

Or as a one-liner:

:set tabstop=4 shiftwidth=4 expandtab

After changing the tab settings run this to change the file to use the new settings:

:retab

MySQL Innodb Optimizations


MySQL Innodb Optimization[1]

  • innodb_buffer_pool_size: InnoDB relies heavily on the buffer pool and should be set correctly, so be sure to allocate enough memory to it. Typically a good value is 70%-80% of available memory
  • innodb_log_file_size[2] - Log file should be big enough to hold at least one hour's worth of transactions. Calculate this using the following (run at peak DB usage time)
  1. SHOW ENGINE STATUS\G
  2. Copy down the value for "Log Sequence Number"  
  3. Wait 60 seconds
  4. SHOW ENGINE STATUS\G
  5. Copy down the new value for "Log Sequence Number"
  6. Subtract the value in Step 5 from the value in Step 2 and multiply by 6 
Eg.
Log sequence number 176285544460
Log sequence number 176286476144

mysql>  SELECT ((176286476144 - 176285544460)*60) / 1024 / 1024;
+--------------------------------------------------+
| ((176286476144 - 176285544460)*60) / 1024 / 1024 |
+--------------------------------------------------+
|                                      53.31138611 |
+--------------------------------------------------+
1 row in set (0.00 sec)


The resulting value is a good approximate  for the size of the log file



[1] https://www.percona.com/blog/2013/09/20/innodb-performance-optimization-basics-updated/
[2] https://www.percona.com/blog/2008/11/21/how-to-calculate-a-good-innodb-log-file-size/

Wednesday, February 3, 2016

GIT stuff

CREATING A FEATURE BRANCH FROM THE DEV BRANCH:

http://stackoverflow.com/questions/4470523/git-create-a-branch-from-another-branch

git branch -b <FEATURENAME> develop
git push origin <FEATURENAME>

-----------

integrating master->develop , or develop->feature
(rebase)

http://stackoverflow.com/questions/16955980/git-merge-master-into-feature-branch

git checkout feature1
git rebase master
Manage all conflicts that arise. When you get to the commits with the bugfixes (already in master), git will say that there were no changes and that maybe they were already applied. You then continue the rebase (while skipping the commits already in master) with
git rebase --skip
-----

rebasing correctly

git fetch
git checkout develop
git pull
git checkout <feature>
git rebase develop


git fetch does not update non-checked out branches by default

---


# Merge local branch foo into local branch master,
# without having to checkout master first.
# Here `.` means to use the local repository as the "remote":
git fetch . foo:master

# Merge remote branch origin/foo into local branch foo,
# without having to checkout foo first:
git fetch origin foo:foo

http://stackoverflow.com/questions/3216360/merge-update-and-pull-git-branches-without-using-checkouts


--------------

Rename Branch

Locally:

If branch checked out:
git branch -m <new_name>

Without branch checked out:
git branch -m <old_name> <new_name>

Remotely:

1) Delete the old branch, and push the local branch up to the new name:
git push origin :old-name new-name

2) Reset the upstream branch for the newly named local branch (with renamed local branch checked out):

git push origin -u new-name






Friday, January 22, 2016

Angular quickstar

Angular quickstart (from CodeSchool) Javascript



app.js:

(function() {
var gem = { name = 'Nick P' };

var app = angular.module('Test', []);
app.controller('StoreController', function() {
this.product = gem;
}
})();
app.html:
<html ng-app="app.js">
<body>
<div ng-controller="StoreController as store">
Product Name: {{store.product.name}}
(Should display "Nick")
</div>
</body>
</html>

"store" is just a locally scoped alias to the StoreController object. It is not available (neither is StoreController) outside the "scope" of the html block in which it is assigned by ng-controller (In this case a div).

My guess is that we want tight scoping on these blocks because interpolating the DOM slows down the page during loading, so we want as little interpolation as possible.

Thursday, January 7, 2016

Yum explodes when libcurl recompiled

Problem:
I've recompiled libcurl and now yum explodes in the following way:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Traceback (most recent call last):
  File "/usr/bin/yum", line 29, in 
    yummain.user_main(sys.argv[1:], exit_code=True)
  File "/usr/share/yum-cli/yummain.py", line 254, in user_main
    errcode = main(args)
  File "/usr/share/yum-cli/yummain.py", line 109, in main
    result, resultmsgs = base.doCommands()
  File "/usr/share/yum-cli/cli.py", line 357, in doCommands
    return self.yum_cli_commands[self.basecmd].doCommand(self, self.basecmd, self.extcmds)
  File "/usr/share/yum-cli/yumcommands.py", line 651, in doCommand
    return base.search(extcmds)
  File "/usr/share/yum-cli/cli.py", line 881, in search
    for (po, keys, matched_value) in matching:
  File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 2118, in searchGenerator
    for sack in self.pkgSack.sacks.values():
  File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 774, in 
    pkgSack = property(fget=lambda self: self._getSacks(),
  File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 564, in _getSacks
    self.repos.populateSack(which=repos)
  File "/usr/lib/python2.6/site-packages/yum/repos.py", line 250, in populateSack
    self.doSetup()
  File "/usr/lib/python2.6/site-packages/yum/repos.py", line 83, in doSetup
    self.ayum.plugins.run('postreposetup')
  File "/usr/lib/python2.6/site-packages/yum/plugins.py", line 179, in run
    func(conduitcls(self, self.base, conf, **kwargs))
  File "/usr/lib/yum-plugins/fastestmirror.py", line 186, in postreposetup_hook
    if downgrade_ftp and _len_non_ftp(repo.urls) == 1:
  File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 679, in 
    urls = property(fget=lambda self: self._geturls(),
  File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 676, in _geturls
    self._baseurlSetup()
  File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 630, in _baseurlSetup
    mirrorurls.extend(self._getMirrorList())
  File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 1668, in _getMirrorList
    fo = urlgrabber.grabber.urlopen(url, **ugopts)
  File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 628, in urlopen
    return default_grabber.urlopen(url, **kwargs)
  File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 926, in urlopen
    return self._retry(opts, retryfunc, url)
  File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 886, in _retry
    r = apply(func, (opts,) + args, {})
  File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 925, in retryfunc
    return PyCurlFileObject(url, filename=None, opts=opts)
  File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 1066, in _init__
    self._do_open()
  File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 1353, in _ do_open
    self._set_opts()
  File "/usr/lib/python2.6/site-packages/urlgrabber/grabber.py", line 1196, in _ set_opts
    self.curl_obj.setopt(pycurl.SSL_VERIFYHOST, opts.ssl_verify_host)
pycurl.error: (43, '')

Solution:

The easiest solution is to disable the SSLVerify option in the yum conf.


  1. edit /etc/yum.conf , (or /etc/yum/yum.conf  depending on your version)
  2. Look for a line under [main] reading sslverify=1
    1. If it exists, change the value to 0
    2. If it doesn't exist, add sslverify=0 to the main block
  3. Viola! your yum should be fixed now

MySQL CSV Export

SELECT <fieldset>
INTO OUTFILE '<output-filename>'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM ....