This commit is contained in:
Rico Sta. Cruz 2017-02-20 17:25:13 +08:00
parent 212bf44a31
commit 99f4eeef63
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
6 changed files with 271 additions and 1 deletions

81
_drafts/ansible.md Normal file
View File

@ -0,0 +1,81 @@
---
title: Ansible
category: Ruby
---
## Looping
### Array (with_items)
```yaml
vars:
security_groups:
- name: 'hello'
desc: 'world'
- name: 'hola'
desc: 'mundo'
tasks:
- name: Create required security groups
ec2_group:
name: "{{ item.name }}"
description: "{{ item.desc }}"
with_items: "{{ security_groups }}"
```
### Object (with_dict)
```yaml
tasks:
- name: Print phone records
debug: msg="User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
with_dict: "{{ users }}"
```
## with_file
```yaml
- name: "Send key"
ec2_key:
key_material: "{{ item }}"
with_file: ./keys/sshkey.pub
# or
with_fileglob: ./keys/*.pub
```
### Conditionals
```yml
- include: setup-debian.yml
when: ansible_os_family == 'Debian'
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") or
(ansible_distribution == "Debian" and ansible_distribution_major_version == "7")
# Just like "and"
when:
- ansible_distribution == "CentOS"
- ansible_distribution_major_version == "6"
```
## Expressions
```
{{ item }}
{{ item.name }}
{{ item[0].name }}
{{ item | default('latest') }}
```
## Includes
```
tasks:
- include: wordpress.yml
vars:
wp_user: timmy
```

View File

@ -64,3 +64,8 @@ category: Ansible
- name: do something locally
local_action: shell echo hello
### debug
- debug:
msg: "Hello {{ var }}"

15
cidr.md Normal file
View File

@ -0,0 +1,15 @@
---
title: CIDR
category: Misc
---
| Range | First IP | Last IP |
| --- | --- | --- |
| **10.0.0.0/24** | 10.0.0.0 | 10.0.0.255 |
| **10.0.0.0/16** | 10.0.0.0 | 10.0.255.255 |
| **10.0.0.0/8** | 10.0.0.0 | 10.255.255.255 |
| **0.0.0.0/0** | (all) | (all) |
## Resources
- [CIDR range calculator](http://ipaddressguide.com/cidr#range)

View File

@ -93,3 +93,19 @@ Start each example with `complete -c cmdname`
-a "(cat /etc/passwd | cut -d : -f 1)"
# first argument as filename
### Keys
| `Alt ←` `Alt →` | Move word |
| `^U` | delete to beginning |
| `^W` | delete to previous `/` |
| `Alt D` | delete next word |
{:.shortcuts}
| `Alt H` | help on word (man) |
| `Alt W` | help on word (short descriptions) |
| `Alt L` | list directory on cursor |
{:.shortcuts}
| `Alt ↑` | search keywords |
{:.shortcuts}

View File

@ -15,7 +15,7 @@ category: Devops
heroku access:remove me@xy.com
# Transfer to another owner
heroku sharing:transfer new@owner.com
heroku apps:transfer new@owner.com
### `logs` - Show logs

153
typescript.md Normal file
View File

@ -0,0 +1,153 @@
---
title: TypeScript
category: JavaScript libraries
---
TypeScript is just like ES2015 with type-checking. All ES2015 (classes, etc) should work.
## Basic types
```ts
any
void
boolean
number
string
null
undefined
string[] /* or Array<string> */
[string, number] /* tuple */
string | null | undefined /* union */
never /* unreachable */
```
```ts
enum Color {Red, Green, Blue = 4}
let c: Color = Color.Green
```
## Declarations
```ts
let isDone: boolean
let isDone: boolean = false
```
```ts
function add (a: number, b: number): number {
return a + b
}
// Return type is optional
function add (a: number, b: number) { ... }
```
## Type assertions
```ts
let len: number = (input as string).length
let len: number = (<string> input).length /* not allowed in JSX */
```
## Interfaces
### Inline
```ts
function printLabel (options: { label: string }) {
console.log(options.label)
}
// Note the semicolon
function getUser (): { name: string; age?: number } {
}
```
### Explicit
```ts
interface LabelOptions {
label: string
}
function printLabel(options: LabelOptions) { ... }
```
### Optional properties
```ts
interface User {
name: string,
age?: number
}
```
### Read only
```ts
interface User {
readonly name: string
}
```
### Dynamic keys
```ts
{
[key: string]: Object[]
}
```
## Type aliases
```ts
type Name = string | string[]
```
## Function types
```ts
interface User { ... }
function getUser(callback: (user: User) => any) { callback({...}) }
getUser(function (user: User) { ... })
```
## Classes
```ts
class Point {
x: number
y: number
static instances = 0
constructor(x: number, y: number) {
this.x = x
this.y = y
}
}
```
## Generics
```ts
class Greeter<T> {
greeting: T
constructor(message: T) {
this.greeting = message
}
}
let greeter = new Greeter<string>('Hello, world')
```
## Modules
```
export interface User { ... }
```