Skip to content

Instantly share code, notes, and snippets.

@sitex
sitex / 0_reuse_code.js
Created June 10, 2016 03:33
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
Exercises from Workshop 2015 day 1
Simple Quyering
'id', 'name' of countries
'id', 'population' of countries
sum of 'population' of all countries (method 1)
sum of 'population' of all countries (method 2)
count of continents (with Collection)
count of continents (with PHP)
Associations
Countries speaking certain language
<?php
function validate_email($email)
{
$email_host = array_pop(explode('@', $email));
if (checkdnsrr($email_host, 'MX)) {
return true;
} else {
return false;
}
}
docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.0-cli php file.php
<?php
class dnsRecord {
private $domain = '';
private $subdomains = [];
private $type = 'MX';
private $filter = null;
private $check;
public function __construct($domain = '', $subdomains = [], $type = '', $filter = null)
dig mail.yandex.ru @ns1.yandex.ru A +short
<?php
$arr = [
['id' => 123, 'name' => 'Joe'],
['id' => 345, 'name' => 'Sally']
];
array_column($arr, null, 'id'); // [ 123 => ['id' => 123, 'name' => 'Joe'] ...
array_column($arr, 'name', 'id'); // [ 123 => 'Joe', 345 => 'Sally' ...
<?php
function array_map_filter($fn, ...$arr)
{
return array_filter(array_map($fn, ...$arr));
}
///////////////////////////////////////////
$users = [
[ 'id' => 1, 'name' => 'Joe' ],
<?php
$users = [ 'Joe', 'Bob', 'Sam' ];
array_map(function ($name, $position) {
return compact('position', 'name');
}, $users, range(1, count($users)));
// [ position => 1, name => 'Joe' ]
// [ position => 2, name => 'Bob' ]
// [ position => 3, name => 'Sam' ]
// Controller views are very simple
class HomePageController extends React.Component {
// Normal Flux store listening
componentDidMount() {
Store1.on('change', this.onStoreChange);
Store2.on('change', this.onStoreChange);
}
onStoreChange() {