Skip to content

Instantly share code, notes, and snippets.

View aramis-it's full-sized avatar

ulziibadrakh aramis-it

  • Mongolia
View GitHub Profile
<?php
class ExamplesUsersTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('examples_users');
$this->displayField('id');
$this->primaryKey('id');
@aramis-it
aramis-it / srt_extract.php
Created July 21, 2016 10:21
From http://localhost/spot/members/sources
$this->viewBuilder()->layout('trans');
$source = $this->Sources->newEntity();
if ($this->request->is('post')) {
$source->path = md5(Time::now()) . '.srt';
$file = new File($this->request->data['file']['tmp_name']);
$file->copy(WWW_ROOT . 'files' . DS . $source->path);
$source->title = $this->request->data['title'];
$source->user_id = $this->Auth->user('id');
$this->Sources->save($source);
@aramis-it
aramis-it / pagination.php
Created November 16, 2016 02:55
pagination, cakephp 3, bootstrap 4
<nav aria-label="Page navigation">
<ul class="pagination">
<?php
$this->Paginator->templates([
'prevActive' => '<li class="page-item"><a class="page-link" href="{{url}}">{{text}}</a></li>'
]);
$this->Paginator->templates([
'prevDisabled' => '<li class="page-item disabled"><a class="page-link" href="{{url}}">{{text}}</a></li>'
]);
?>
@aramis-it
aramis-it / controller.php
Created November 18, 2016 02:43
cakephp 3 update entity
<?php
$translation = $this->Translations->patchEntity($translation, $this->request->data, [
'validate' => false,
'associated' => ['SentenceTranslations' => ['accessibleFields' => ['id' => true]]]
]);
@aramis-it
aramis-it / jquery-confirm.js
Created January 20, 2017 06:00
Jquery confirm before submit
$("form").submit(function (e) {
if (confirm("Bla bla")) {
} else {
e.preventDefault(e);
}
});
@aramis-it
aramis-it / CorsMiddleware.php
Last active June 12, 2021 00:32
Hide trello first board
<?php
declare(strict_types=1);
namespace App\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
@aramis-it
aramis-it / ObjectProperty.js
Last active August 8, 2018 01:44
General form event listener direct field , object property
// form event field
onFieldChange = e => {
this.setState({ [e.target.name]: e.target.value });
};
// form event Object property
onPropertyChange = e => {
this.setState({
[e.target.dataset.model]: {
...this.state[e.target.dataset.model],
@aramis-it
aramis-it / object.js
Created November 29, 2018 02:27
Iterate, loop through object properties
Object.keys(obj).forEach(e => console.log(`key=${e} value=${obj[e]}`));
@aramis-it
aramis-it / groupByField.js
Created November 29, 2018 02:28
array group by field
groupBy(xs, key) {
return xs.reduce(function(rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
}
@aramis-it
aramis-it / promize.js
Created February 17, 2019 08:03
Promise all
Promise.all([get("/v1/languages.json"), get("/v1/profiles.json")]).then(
values => {
}
);