Skip to content

Commit

Permalink
Added a bunch of existing notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Hermosilla committed Jul 19, 2017
1 parent c7aa8c0 commit b6ba1b5
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bash.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# Bash

https://www.shellcheck.net/

## Learning
- https://cmdchallenge.com/
- https://explainshell.com/

### Bash Tips
- http://www.kfirlavi.com/blog/2012/11/14/defensive-bash-programming/ <- **MUST READ**
- https://google.github.io/styleguide/shell.xml
- https://www.blockloop.io/mastering-bash-and-terminal
- https://php-and-symfony.matthiasnoback.nl/2017/03/bash-practices-input-validation-and-local-variables/
- http://tuxtweaks.com/2014/05/bash-getopts/
- http://redsymbol.net/articles/unofficial-bash-strict-mode/
- http://redsymbol.net/articles/bash-exit-traps/
- http://unix.stackexchange.com/questions/97101/how-to-catch-an-error-in-a-linux-bash-script
Expand All @@ -9,3 +20,9 @@
- http://www.linuxjournal.com/content/bash-sub-shells
- https://stelfox.net/blog/2013/11/fail-fast-in-bash-scripts/
- http://rockhopper.monmouth.edu/cs/jchung/cs370/cs_370_-_subshells_and_parallel_processing
- https://jvns.ca/blog/2017/03/26/bash-quirks/

## Windows
**Windows cmd.exe access BASH WSL**
`cd %localappdata%\Lxss\ && dir`
- https://remysharp.com/2017/06/26/windows-10-bashing
115 changes: 115 additions & 0 deletions bin/list_modules.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/usr/bin/perl

# cpan modules were installed say a year ago. If you
# cpan install that same module on another system it
# will be a different version. With cpanm/cpanfile
# you can specify a version. This tool allows you
# to dump a cpanfile compatible formatted output of
# the current environments module versions.
#
# @example output
# requires 'Proc::Daemon', '== 0.14';
#
# @usage
# To see all modules with version
# ./list_modules.pl
#
# To see a filtered down list
# ./list_modules.pl MongoDB,Beanstalkd,Dumper
#
# @notes
# - use cpanminus!
# `curl -L https://cpanmin.us | perl - --sudo App::cpanminus`
# `cpanm --installdeps .`
# - Another way to see installed modules perldoc perllocal

use strict;
use ExtUtils::Installed;

my @filtered = map {split(/,/, $_)} @ARGV;
my $filter_count = scalar @filtered;

my $inst = ExtUtils::Installed->new();
my @modules = $inst->modules();
my %modules_map = map { $_ => 1 } @modules;

my $file = '';
my $files;
my $version;
my @matched = ();

sub add_module_info {
my $module_name = shift;
$version = $inst->version($module_name);
push @matched, "requires '$module_name', '== $version';";
}

sub print_list {
my $list_ref = shift;
my @list = sort @{$list_ref};

foreach my $match (@list) {
print "$match\n";
}
}

sub already_matched {
my $module_name = shift;
my @found = grep(/$module_name/, @matched);
my $matched_x = scalar @found;
return ($matched_x ne 0);
}

sub is_in_filter {
my $module_name = shift;
foreach my $filter (@filtered) {
if (index($module_name, $filter) != -1) {
return 1;
}
}

return 0;
}

foreach my $module (@modules) {
# Checking for filter matches
if ($filter_count gt 0) {
if (!is_in_filter($module)) {
next;
}
}

add_module_info($module);
}

# Checking for filter matches
if ($filter_count eq 0) {
print_list(\@matched);
exit 0;
}

my @missing = ();

# Post process and make sure to check each module
# name explicitly provided
foreach my $filter (@filtered) {
if (already_matched($filter)) {
next;
}

my ($module_ns, $submodule) = split(/::/, $filter);

if (already_matched($module_ns)) {
next;
}

if(exists($modules_map{$module_ns})) {
add_module_info($module_ns);
} else {
push @missing, "# Missing: requires '$filter', '== x.y.z';";
}
}

print_list(\@matched);
print_list(\@missing);
exit 0;
17 changes: 17 additions & 0 deletions git.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# git

- Files changes in a commit
`git diff-tree --no-commit-id --name-only -r c06d5186ed7`
- Last commit files changes
`git rev-parse HEAD | xargs -I {} git diff-tree --no-commit-id --name-only -r {}`
- Current files
`git status -s | grep php | sed 's/^ *//' | cut -d' ' -f2`
- Pipe to lint quickly
`xargs -I {} php -l {}`
`git rev-parse HEAD | xargs -I {} git diff-tree --no-commit-id --name-only -r {} | xargs -I {} php -l {}`
- Php file changes in a merge
`git log -1 --name-only | grep '.php' | xargs -I{} php -l {}`
- Show files changes between branches
`git diff remotes/origin/master remotes/origin/security-tweak --name-only`
- Git show pending merges
`git show-ref | grep merge | cut -d' ' -f1 | xargs -I{} git show {}`
16 changes: 16 additions & 0 deletions mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ query="{class: 0, ts: {\$gt: ${second_ago} }}"
mongo Health --eval "db.Stats.findOne($query).ts" &>/dev/null
```



## Export
**Snapshot**
`mongodump --quiet -d User -o /data/snapshot/user-$(date +%Y%m%d)`
Expand All @@ -31,4 +33,18 @@ restore_data()
mongo User --eval "$reindex" &>/dev/null
mongo Health --eval "$reindex" &>/dev/null
}
```

## Schema Inspection
With `variety.js` you can inspect a collection's schema, to get an idea of the field names and data types!

https://github.com/variety/variety


```bash
product_class=2
hours_ago=$(date -d '8 hour ago' "+%s")
query="{'class': ${product_class}, 'ts': {'\$gt': ${hours_ago} }}"

mongo Health --quiet --eval "var collection='Stats', query=${query}, outputFormat='json', limit=3000, maxDepth=1" variety.js
```
11 changes: 11 additions & 0 deletions mysql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# MySql

**Flags to provide password in file**
`--defaults-file=user_pass.cnf`
`--login-path`

## Links
- https://speakerdeck.com/samlambert/the-mysql-ecosystem-at-github-2015
- https://www.percona.com/blog/2017/03/06/mysql-i-am-a-dummy/
- https://twindb.com/use-proxysql-tools/
- http://code.openark.org/blog/mysql/whats-so-complicated-about-a-master-failover
19 changes: 19 additions & 0 deletions php.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# PHP


## Code Standards
```shell
composer global require phpmd/phpmd
composer global require "squizlabs/php_codesniffer=*"
phpcs --config-set default_standard PSR

filename=test.php

# Use mess detector!
phpmd ${filename} text codesize,unusedcode,naming,design

# Use Code style checker
phpcs ${filename}`
# To fix fails phpcbf is your friend!
phpcbf ${filename}
```

0 comments on commit b6ba1b5

Please sign in to comment.