Learning Log
2017-01-12-13-39-37
Yield in PHP
Yield is a keyword that returns data from a generator function.
https://stackoverflow.com/questions/17483806/what-does-yield-mean-in-php
If normal iteration requires an entire array to be in memory, a generator function only requires the data at hand to be in memory. e.g. UPS vs Ping pong.
January 26, 2016 to present
Delete all git tags
#Delete local tags.
git tag -l | xargs git tag -d
#Fetch remote tags.
git fetch
#Delete remote tags.
git tag -l | xargs -n 1 git push --delete origin
#Delete local tags.
git tag -l | xargs git tag -d
from https://gist.github.com/okunishinishi/9424779
phing psr-fix
wiki.theory.org/YourLanguageSucks
urlencode
This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.
string urlencode ( string $str )
php.net/manual/en/function.urlencode.php
error: missing parent constructor call
Calling a parent's contructor in php
parent::__construct();
/**
* @param MyClass $myInstance
*/
public function __construct(MyClass $myInstance = null)
{
parent::__construct();
if (!$myInstance instanceof MyClass) {
$myInstance = new UserCollection();
}
$this->myInstance = $myInstance;
}
Mock repositories will be needed to make sure the services can be provided to the controllers.
- added to composer
Various ways to discard changes in git:
git checkout . # Removes Unstaged Tracked files ONLY [Type 2]
git clean -f # Removes Unstaged UnTracked files ONLY [Type 3]
git reset --hard # Removes Staged Tracked and UnStaged Tracked files ONLY[Type 1, Type 2]
git stash -u # Removes all changes [Type 1, Type 2, Type 3]
http://stackoverflow.com/questions/22620393/various-ways-to-remove-local-git-changes
Why does JSON require double quotes?
- StackOverflow: is-there-any-practical-reason-to-use-quoted-strings-for-json-keys
- StackOverflow: son-spec-does-the-key-have-to-be-surrounded-with-quotes
- StackOverflow: in-json-why-is-each-name-quoted
save composer requirement
composer require "touchlab/thunderdome-php=dev-stable"
Selenium
- Page Object Model & Selenium #bestPractice
- Ruby inheritence vs extends
- page object gem
text_field()
create methods you can call on the class
page = LoginPage.new
# ...same as
visit LoginPage do |page| ...
sleep
is bad. Use expect {}.to change {} ... expect().to eq ...
Why runner
, rathre than rspec
directly?
- deletes webapp logs
- runs in parallel
- Javascript Spread Operator
- Type Theory
- Finagle
- Thrift
- XPath & selectors
Looking into Auto-Complete Tools
- Twitter's Typeahead
-
- More active development
- Tailored for React
Avoid inheritance hierarchies when possible since they're more limiting than reusable
duplicate a directory, preserving rights, symlinks...
cp -a src target
# -a, --archive, same as -dR --preserve=all
Backbone.js
HTML: maxlength
The maximum number of characters allowed in the <input>
element. Default value is 524288
.
<input maxlength="number">
example:
<form action="demo_form.asp">
Username: <input type="text" name="usrname" maxlength="10"><br>
<input type="submit" value="Submit">
</form>
From: SourceMaking
Builder Pattern: Separates object construction from its
- Decorator Pattern + Chain of Command
- Inheritence Hierarchy
- Specification Pattern
- Traits vs. Interface within Scala
- Dependency fetching vs injection
- BitMask
- Futures
- Promises
- React Router
Intro to...
Webpack, ES6, Babel, React, Redux, & React-Redux
.php
and .phtml
are synonymous, interpreted exactly the same.
From: StackOverflow
.phtml
was the standard file extension for PHP 2 programs..php3
took over for PHP 3. When PHP 4 came out they switched to a straight.php
.
With the GitBook YouTube plugin, embed videos using:
{% youtube %}https://www.youtube.com/watch?v=9bZkp7q19f0{% endyoutube %}
git fetch --tags --prune
to ad the Todo plugin to gitbook
npm install --save gitbook-plugin-todo
Then add this to your book.json
{
"plugins": ["todo"]
}
speed up git status
by not showing untracked files:
git status --untracked-files=no
Which is the same as:
git status -uno
Useful with very large projects.
green fielding: creating new code
setting a specific port with gitbook serve
:
gitbook --port 3000 serve
Created a HSTS entry. Wikipedia article
2016-04-18
Create symlinks for appropriate brew apps
brew linkapps <app_name_or_blank>
Experimenting with Emacs because I'm interested in org-mode.
StackOverflow: What is the difference between Aquamacs and other Mac versions of Emacs?
brew install emacs --HEAD --use-git-head --with-cocoa --with-gnutls --with-rsvg --with-imagemagick
spray routes: http://spray.io/documentation/1.1.2/spray-routing/
From: Akka: actor system
An actor system is a hierarchical group of actors which share common configuration, e.g. dispatchers, deployments, remote capabilities and addresses. It is also the entry point for creating or looking up actors.
2016-04-13
Gitbook, within
SUMMARY
CAN-SPAM Act of 2003
The CAN-SPAM Act of 2003, signed into law by President George W. Bush on December 16, 2003, establishes the United States' first national standards for the sending of commercial e-mail and requires the Federal Trade Commission (FTC) to enforce its provisions.
- Why emails need an unsubscribe link in emails.
- Wikipedia Link
2016-04-11
chmod 755 <script_name>
making a ruby script executable
2016-03-29
array_filter()
2016-03-25
foreach()
in PHP is destructive; clone the enumerable prior to use:foreach(clone $myStuff as $thing) {...};
2016-03-22
Namespace leaks with a
foreach()
loop in PHP$testVar = ['yo', 'mario']; foreach($testVar as $t) {} echo $t;
mario
Kintsugi (金継ぎ?) (Japanese: golden joinery) or Kintsukuroi (金繕い?) (Japanese: golden repair) is the Japanese art of repairing broken pottery with lacquer dusted or mixed with powdered gold, silver, or platinum, a method similar to the maki-e technique. As a philosophy it treats breakage and repair as part of the history of an object, rather than something to disguise. https://en.wikipedia.org/wiki/Kintsugi
Kaizen (Continuous Improvement) is a strategy where employees at all levels of a company work together proactively to achieve regular, incremental improvements to the manufacturing process. In a sense, it combines the collective talents within a company to create a powerful engine for improvement. http://www.leanproduction.com/kaizen.html
2016-03-21
Changing the author of the last commit
git commit --amend --author="John Doe <[email protected]>"
http://stackoverflow.com/questions/3042437/change-commit-author-at-one-specific-commit
gatling.io
Load testing framework written in Scala
In PHP, using the
final
keyword with a class or method prevents child classes from overriding it, whether with a new method declaration or a class extesion. (PHP.net)<?php final class BaseClass { public function test() { echo "BaseClass::test() called\n"; } // Here it doesn't matter if you specify the function as final or not final public function moreTesting() { echo "BaseClass::moreTesting() called\n"; } } class ChildClass extends BaseClass { } // Results in Fatal error: Class ChildClass may not inherit from final class (BaseClass) ?>
In PHP,
array_key_exists()
will tell you if a key exists in an array,isset()
will only returntrue
if the key/variable exists and is notnull
.
2016-03-17
Grabbing command line arguments from a PHP script
getopt
(php.net)
$shortopts = ""; $shortopts .= "f:"; // Required value $shortopts .= "v::"; // Optional value $shortopts .= "abc"; // These options do not accept values $longopts = array( "required:", // Required value "optional::", // Optional value "option", // No value "opt", // No value ); $options = getopt($shortopts, $longopts);
php example.php -f "value for f" -v -a --required value --optional="optional value" --option
array(6) { ["f"]=> string(11) "value for f" ["v"]=> bool(false) ["a"]=> bool(false) ["required"]=> string(5) "value" ["optional"]=> string(14) "optional value" ["option"]=> bool(false) }
2016-03-16
Parse a csv file in PHP (from php.net)
$csv = array_map('str_getcsv', file('data.csv'));
What I've worked on recently:
2016-03-15
Change mode to be executable:
chmod +x <file>
; nothing new here, but I thinking of it as chmod, not change mode. I think the latter will be easier to remember.paste this into your browser console to beautify formatting
var sheet = document.createElement('style'); sheet.innerHTML = "body{margin: 40px auto;max-width: 650px;line-height: 1.5;font-size: 18px;color: #3a3a3a;padding: 0 10px;}"; document.body.appendChild(sheet);
2016-03-14
UML diagram w/i PhpStorm:
- install plugin (it's the only UML one)
- select dir
⇧
+⌥
+⌘
+u
git: show files updated/created in the past x days
git log --pretty=format: --name-only --since="3 days ago" | sort | uniq
What I've worked on recently:
2016-03-07
Run this JS at read.amazon.com to get copy/paste functionality (from https://gist.github.com/aaronshaf/1346968)
new_window=window.open();new_window.document.body.innerHTML = $('iframe').contents().find('iframe').contents().find('body').get(1).innerHTML;
2016-02-26
Set configs for an atom project across IDEs: https://atom.io/packages/editorconfig
Looking into linting my markdown
Remark Lint, built on Remark. Rules can be found here
npm install --global remark remark-lint
configure with
.remarkrc
{ "plugins": { "lint": { "no-multiple-toplevel-headings": true, "list-item-indent": true, "maximum-line-length": false, "ordered-list-marker-value": false, "no-duplicate-headings": false } }, "settings": { "commonmark": true } }
2016-02-24
- my focus has been on learning LDAP the past few days.
- a gitbook plugin to handle checkmarks: github.com/LingyuCoder/gitbook-plugin-todo
2016-02-23
- I have a love/hate relationship with Xdebug and PhpStorm. When it works, I love debugging.
2016-02-18
- vim macros
- Law of Demeter
- Exercism.IO, a tool to learn languages.
- symbol in ruby: an immutable value that only uses one slot of memory.
- Intersection /
&
in ruby
2016-02-17
remove a remote repo in git
git remote rm <remote_name>
calling a parent method in ruby:
From: StackOverflow
If the method is the same name, i.e. you're overriding a method you can simply use super. Otherwise you can use an alias_method or a binding.
class Parent def method end end class Child < Parent alias_method :parent_method, :method def method super end def other_method parent_method #OR Parent.instance_method(:method).bind(self).call end end
copy the contents of
id_rsa.pub
to your clipboardpbcopy < ~/.ssh/id_rsa.pub
2016-02-16
renaming a remote branch in git
git remote rename origin destination
push to all remotes in git
git remote | xargs -L1 git push --all
2016-02-15
gitbook plugin to collapse chapters: gitbook-plugin-collapsible-menu. Can be found in the GitBook Plugin Directory
use
sprintf()
to create a template to construct a string. #PHPconst FORMAT_MESSAGE = 'The screen name "%s" already exists.'; sprintf(static::FORMAT_MESSAGE, $screenName->getValue()));
2016-02-12
change author of last git commit
git commit --amend --author="Chris Torsten <[email protected]>"
attr_reader(*ATTR_READERS)
gets rid of never-ending arguments afterattr_reader
{@inheritdoc}
within a PHPDoc inherits the long description from the parent class.
2016-02-10
to get the size of a path:
$ du
du -hs
gives just the dir it's run in- man page
git shallow commit
git clone --<depth>::
creates a shallow clone with a truncated history to a specifed depth.- Although not recommended, you can
push
andpull
from it
2016-02-09
With an optional property (which is a class itself) within a PHP class, It's a good idea to create a Null version of the class that is returned by default if the argument is null.
NullMyPropClass->getValue() # returns an empty string.
You could also return
null
, but there is value in always returning the same type.
2016-02-05
- typing
f
using vimium is a great way to navigate a web page. - typing
f
while on a gitbook page brings up search.
2016-02-04
- Kitematic, a nice tool to interact with your docker images.
- Playing around with Huginn, an interesting agent tool, like IFTTT (here's a nice video). ...pretty sure it's logo and name alude to one of my favorite authors, Daniel Suarez.
2016-02-03
http://readable.tastefulwords.com/ Great tool to make a site readable.
Phing (PHing Is Not GNU make)
it's a PHP project build system or build tool based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework.
To zero out a css transform, which you may want to do if it leaves junk pixels...
.modal-shadow .modal { -webkit-transform: none; transform: none; }
2016-02-02
- Interetesting article (https://speakerdeck.com/vjeux/react-css-in-js) about inlining styles in React.
- TODO process notes from https://stash.corp.creditkarma.com/projects/MAX/repos/admax-js/pull-requests/141/overview
2016-02-01
Week of 2016-02-01
Switching to a Twitter-esque sorting
Learning Log
Week of 2016-01-25
2016-01-26
Playing around with GitBook. Not yet settled on how I want to store/publish my notes.
partly inspired by John's notes: github.com/qsymmachus/notes, I think the most valuable element of that inspiration may very well be the learning log concept.
Laravel/Lumen Container: manages class dependencies and aids with dependency injection, by "binding" dependency interfaces to dependency implementations. These bindings are registered in Service Providers. An instance of Container is available in all Service Providers as
app
:return new MailgunMailer($app[Credentials::class]) })
Any time an object has
Mailer
injected as a dependency, the Container will inject this particular instance. As illustrated above, you can resolve bindings from the Container with the following syntax:$this->app[SomeClass::class] $this->app->make(SomeClass::class) // alternate syntax $this->app->bind(Mailer::class, function ($app) {}
playing around with using gitbooks.io to publish this repo, you can find it here: https://torsday.gitbooks.io/notebook/content/learning_log.html
2016-01-27
To commit case-sensitive only filename changes in Git:
git config core.ignorecase false
2016-01-28
When you use
EventCollection
with an iteration operator such asforeach
, it pops each element off, destroying the data structure. You may need to useclone
:foreach (clone $this->accountStatusEvents as $e) { $serializedEvents[] = EventJsonSerializerFactory::create($e); }
$this->assertCount($expectedInt, $countableObj);
$eventCollection = new EventCollection(); $count = count($eventCollection); // 0
How it works:
EventCollection
extendsCollection
which extendsSplMaxHeap
(http://php.net/manual/en/class.splmaxheap.php) which implementsCountable
(http://php.net/manual/en/class.countable.php).Private functions should be positioned below public ones in PHP.
upgrade npm packages
Identify out of date packages (
npm outdated
). Update the versions in yourpackage.json
. Runnpm update
to install the latest versions of each package.font awesome has a nice history icon
to make an image appear in markdown, make a link with an exclamation point prepended to it.

CSS to use system fonts on mobile devices:
font-family: system, -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
Sleep display
pmset displaysleepnow
empty directories
# list find . -type d -empty -print # delete find . -type d -empty -delete
git branch authors
git for-each-ref --format='%(committerdate)%09%(authorname)%09%(refname)' | sort -k5n -k2M -k3n -k4n | grep remotes | awk -F "\t" '{ printf "%-32s %-27s %s\n", $1, $2, $3 }'
git merged remote branches
for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r
git un-merged remote branches
for branch in `git branch -r --no-merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | sort -r
rename extensions of files in a dir
find . -name "*.rb" -exec bash -c 'mv "$1" "$(sed "s/\.rb$/.md/" <<< "$1")"' - '{}' \;
2016-01-29
Shift+Esc
to clear all slack channel notifications
TODO: outline likely CK files to create
kamino/modal
// JSX return ( <Modal nox ref="something" > content </Modal> ); // Javascript ES6 this.refs.something.show(); -> show modal this.refs.something.hide(); -> hide modal
git stage part of file
git add -p
TODO bind in Javascript
Reminded about how useful inserting
debugger
into my JS code can be when combined with Chrome.