Skip to content

Instantly share code, notes, and snippets.

View cebe's full-sized avatar
☁️
working on cebe.cloud

Carsten Brandt cebe

☁️
working on cebe.cloud
View GitHub Profile
@cebe
cebe / Makefile
Last active January 25, 2023 09:49
How to run docker commands as your local user, not root
# This is a Makefile that implements helpers for a docker stack
#
# This example shows how to run a bash in a docker-compose container as your local user,
# so files are created owned by that user instead of root.
#
# For this to work, the user inside the container must have the same ID as the user outside.
# The name does not matter much but to avoid confusion it is helpful to make them have the same user name.
# You get a users ID by running the `id -u` command, and the users name is `whoami`.
#
# How it works:
<?php
// add a spinner to the upload button when it is clicked
$this->registerJs(<<<JS
$('#import-form').on('beforeSubmit', function() {
var button = $(this).find('#import-submit-button');
button.prop('disabled', true);
button.append(' <i class="fa fa-spinner fa-spin"></i>');
});
JS
@cebe
cebe / PHP-Array.groovy
Created March 25, 2021 10:35
PHP Array exporter for PHPStorm
/*
* Based on IntelliJ PHPStorm JSON exporter.
*
* Available context bindings:
* COLUMNS List<DataColumn>
* ROWS Iterable<DataRow>
* OUT { append() }
* FORMATTER { format(row, col); formatValue(Object, col); getTypeName(Object, col); isStringLiteral(Object, col); }
* TRANSPOSED Boolean
* plus ALL_COLUMNS, TABLE, DIALECT
@cebe
cebe / objectToArray.php
Created June 19, 2019 08:36
workaround for object to array cast in PHP <7.2.0
<?php
// workaround for object to array cast in PHP <7.2.0
// https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts
// https://3v4l.org/05SPE
private function objectToArray($object)
{
if (PHP_VERSION_ID < 70200) {
// work around PHP bug https://3v4l.org/05SPE
// https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts
if (is_object($object)) {
@cebe
cebe / view.php
Created June 3, 2019 15:48
Bootstrap 3 responsive level indicator
<!-- put this code directly after <body> tag, for non-Yii environment, skip the if() statement -->
<?php if (YII_DEBUG): ?>
<!-- bootstrap responsive level indicator, only shown in debug mode -->
<div style="position: fixed; top: 0; left: 0; background: white; border: solid 1px #ccc; width: 25px; height: 18px; text-align: center; font-size: 10px; font-weight: bold; opacity: 0.5; z-index: 10000;" title="bootstrap responsive level indicator">
<span class="visible-xs-inline">xs</span>
<span class="visible-sm-inline">sm</span>
<span class="visible-md-inline">md</span>
<span class="visible-lg-inline">lg</span>
</div>
<?php endif; ?>
@cebe
cebe / Mongodb Cache.php
Last active September 27, 2018 10:35 — forked from Abiraman/Mongodb Cache
// My code
<?php
$collection=\app\models\Notifications::getCollection()->name;
if ($this->beginCache('Notifghjgjhgication', ['dependency' => [
'class' => 'yii\caching\DbQueryDependency',
'query' => \app\models\Notifications::find()->where(["receiver_type" => "vendor", "receiver_id" => \Yii::$app->user->identity->_id, 'read_status' => FALSE]),
'method' => 'count',
]])) {?>
<li class="dropdown" id="Notification-list-container">
<?= Yii::$app->runAction('/notification/default/notificationlist') ?>
@cebe
cebe / abc.sls
Last active November 22, 2017 06:55 — forked from tom--/abc.sls
a:
lorem.ipsum
x:
lorem.dolor
y:
lorem.sit
b:
@cebe
cebe / remote-git.sh
Created October 25, 2017 20:39
quick remote git repo
# prepare server
ssh root@10.0.3.39
git init --bare /srv/testrepo.git
exit
# in local repo
git remote add testrepo root@10.0.3.39:/srv/testrepo.git
@cebe
cebe / neo4j.conf
Created October 5, 2017 19:17
Neo4j stalt state files
#*****************************************************************
# Neo4j configuration
#
# For more details and a complete list of settings, please see
# https://neo4j.com/docs/operations-manual/current/reference/configuration-settings/
#*****************************************************************
# The name of the database to mount
#dbms.active_database=graph.db
@cebe
cebe / pdobug.php
Last active August 14, 2017 10:30
Reproducing a PHP PDO bug
<?php
$tableSql = <<<SQL
DROP TABLE IF EXISTS `typebug`;
CREATE TABLE `typebug` (
`int_col` integer NOT NULL,
`int_col2` integer DEFAULT '1',
`smallint_col` smallint(1) DEFAULT '1',
`char_col` char(100) NOT NULL,
`char_col2` varchar(100) DEFAULT 'something',