Site Tools


onny:notizen:programmierung

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
onny:notizen:programmierung [2022/03/10 17:30] – [wordpress] 185.52.247.41onny:notizen:programmierung [2026/09/08 12:09] (current) – [django] 10.250.0.1
Line 56: Line 56:
 date = datetime.datetime.now().strftime("%d.%m.%Y") date = datetime.datetime.now().strftime("%d.%m.%Y")
 </code> </code>
 +
 requests requests
 +
 <code python> <code python>
 import requests import requests
Line 66: Line 68:
 if (upstream_head.headers['content-type'] == "text/html;charset=UTF-8" or upstream_head.headers['content-type'] == "text/html; charset=UTF-8"): if (upstream_head.headers['content-type'] == "text/html;charset=UTF-8" or upstream_head.headers['content-type'] == "text/html; charset=UTF-8"):
     upstream_response = upstream_response.replace("//thepiratebay.org","")     upstream_response = upstream_response.replace("//thepiratebay.org","")
 +</code>
 +
 +class example
 +
 +<code python>
 +class Planday:
 +  auth_url = 'https://id.planday.com/connect/token'
 +  client_id = '1234'
 +  access_token = ''
 +
 +  def authenticate(self):
 +    payload = {
 +      'client_id': self.client_id,
 +      'refresh_token': 'qyS6qt9yNEqygE1mMQtRzA',
 +      'grant_type': 'refresh_token'
 +    }
 +    headers = {
 +      'Content-Type': 'application/x-www-form-urlencoded'
 +    }
 +    session = requests.session()
 +    session.trust_env = False
 +    response = session.request("POST", self.auth_url, headers=headers, data=payload)
 +    response = json.loads(response.text)
 +    self.access_token = response['access_token']
 +
 +planday = Planday()
 +planday.authenticate()
 </code> </code>
 ==== ponyorm ==== ==== ponyorm ====
Line 176: Line 205:
 </code> </code>
 ===== javascript ===== ===== javascript =====
 +
 +conditional properties in object
 +<code javascript>
 +cont my_object = {
 +  ...(version >= 33 ? { iconSvgInline: MindMapSvg } : { iconClass: 'icon-mindmap' }),
 +}
 +</code>
 +
 split up javascript files split up javascript files
 +
 <code javascript> <code javascript>
 var MODULE = (function (my) { var MODULE = (function (my) {
Line 192: Line 230:
 }(MODULE || {})); }(MODULE || {}));
 </code> </code>
-jquery select by attribute content + 
-<code javascript> +on document ready 
-$( "tr[data-id='"+data[station]["stationid"]+"']" ).remove(); +
-</code> +
-jquery select dynamicly loaded ajax elements+
 <code javascript> <code javascript>
-$('body').on('click','.btn + :not([class=disabled])', function() { +document.addEventListener("DOMContentLoaded", function() { 
-  var link = $(this).attr('src'); +  your_function(...);
-  load_page(link);+
 }); });
 +
 </code> </code>
-jquery set background color + 
-<code javascript> +change content text 
-$(this).parent().css("background-color", "yellow"); +
-</code> +
-print mixed objects +
-<code javascript> +
-console.log('%d: %s', i, value); +
-</code> +
-javascript document ready +
-<code javascript> +
-$(document).ready(function(){ +
-  console.log('ready'); +
-}); +
-</code> +
-vanilla js change content text+
 <code javascript> <code javascript>
     var webgl_field = document.getElementById('webgl');     var webgl_field = document.getElementById('webgl');
Line 226: Line 250:
     }     }
 </code> </code>
-vanilla js ajax post form+ 
 +ajax post form 
 <code javascript> <code javascript>
     document.getElementById('form').onsubmit = function (evt) {     document.getElementById('form').onsubmit = function (evt) {
Line 244: Line 270:
     }     }
 </code> </code>
-vanilla js change style element+ 
 +change style element 
 <code javascript> <code javascript>
     function show_create_post() {     function show_create_post() {
Line 257: Line 285:
  
 trim string to max length trim string to max length
 +
 <code javascript> <code javascript>
 var string = string.substring(0,100); var string = string.substring(0,100);
 </code> </code>
  
-vanilla js onclick class element+onclick class element 
 <code javascript> <code javascript>
 document.getElementsByClassName('navbar-burger')[0].onclick = function(){ document.getElementsByClassName('navbar-burger')[0].onclick = function(){
Line 268: Line 298:
 </code> </code>
  
-add / remove class+onclick on all class elements 
 + 
 +<code javascript> 
 +# old: var anchors = document.getElementsByClassName('wp-block-navigation-item__content'); 
 +let allCheckBox = document.querySelectorAll('.shapes'
 + 
 +  allCheckBox.forEach((checkbox) => {  
 +  checkbox.addEventListener('change', (event) => { 
 +    if (event.target.checked) { 
 +      console.log(event.target.value) 
 +    } 
 +  }) 
 +}) 
 +</code> 
 + 
 +remove class from element 
 + 
 +<code javascript> 
 +var element = document.getElementsByClassName('wp-block-navigation__responsive-container')[0]; 
 +element.classList.remove("is-menu-open"); 
 +</code> 
 + 
 +get url and pathname 
 + 
 +<code javascript> 
 +console.log(window.location.url) 
 +console.log(window.location.pathname) 
 +</code> 
 + 
 +querySelector, get child element 
 + 
 +<code javascript> 
 +var h3 = document.querySelector('div.multicolumn ul li:nth-child(1) h3') 
 +console.log(h3.textContent); 
 +h3.querySelector('span'); 
 +</code> 
 + 
 +querySelectorAll 
 + 
 +<code javascript> 
 +var productAccordion = document.querySelectorAll('div.product__accordion'); 
 +productAccordion[1].style.display = "none"; 
 +</code> 
 + 
 +get next or previous element 
 <code javascript> <code javascript>
-burgerMenu.classList.remove('is-active'); +document.getElementById('foo2').nextSibling// #foo3 
-burgerMenu.classList.add('is-active');+document.getElementById('foo2').previousSibling// #foo1
 </code> </code>
 ==== vuejs ==== ==== vuejs ====
Line 446: Line 521:
       }       }
 </code> </code>
-===== css ===== + 
-sweet font styling +===== php ===== 
-<code css+ 
-font-familyconsolas,Menlo-Regular,Menlo,Monaco,monospace; +printf string 
-    font-size: 125%; + 
-    line-height: 135%;+<code php
 +printf("cleaning criteria%s\n"$config['filterCriteria']);
 </code> </code>
-media queries, page greater than 600px + 
-<code css+print array 
-      @media (min-width: 600px+ 
-        article { +<code php
-          min-width: 600px+$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); 
-        } +print_r($a);
-      }+
 </code> </code>
-popover menu 
-<code css> 
-.main-navigation ul li ul.sub-menu { 
- opacity: 0; 
- position: absolute; 
-  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26); 
- transition:opacity 250ms ease-out; 
- padding: 20px; 
- z-index: 2; 
- left: 17px; 
- background: white; 
-} 
  
-.main-navigation ul li:hover ul.sub-menu { +filter array only unique items 
- opacity: 1; + 
- transition:opacity 250ms ease-out; +<code php> 
-}+$userIds = array_unique($userIds);
 </code> </code>
  
-responsive grid layout +append to array 
-<code> + 
-ul { +<code php
- display: grid+$fruits = ['apple', 'banana']
- grid-gap: 50px 40px; +$fruits[] = 'orange'
- grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); +
-}+
 </code> </code>
-===== php =====+ 
 +assosiative array / dictionary 
 + 
 +<code php> 
 +$myResult["ids"[123, 125, 127]; 
 +</code> 
 + 
 +datetime object, convert to string 
 + 
 +<code php
 +$date new \DateTime('1990-01-01'); 
 +$dateString $date->format('d.m.Y'); 
 +</code> 
 enable debugging / error log enable debugging / error log
 +
 <file - /etc/php/conf.d/debug.ini> <file - /etc/php/conf.d/debug.ini>
 display_startup_errors = true display_startup_errors = true
Line 502: Line 577:
 chmod a+w+r /var/log/php-errors.log chmod a+w+r /var/log/php-errors.log
 </code> </code>
 +
 foreach loop foreach loop
 +
 <code php> <code php>
 foreach($this->service->findAll($this->userId) as $station) { foreach($this->service->findAll($this->userId) as $station) {
Line 512: Line 589:
 } }
 </code> </code>
 +
 get array length get array length
 +
 <code php> <code php>
 var_dump(count($a)); var_dump(count($a));
Line 518: Line 597:
  
 get type of variable get type of variable
 +
 <code php> <code php>
 foreach($data as $episode) { foreach($data as $episode) {
Line 525: Line 605:
  
 convert string to int convert string to int
 +
 <code php> <code php>
 intval("12345"); intval("12345");
Line 535: Line 616:
 </code> </code>
  
 +
 +define class, create object
 +
 +<code php>
 +class Calendar {
 +    private array $data;
 +
 +    public function __construct(array $data) {
 +        $this->data = $data;
 +    }
 +
 +    public function getUserId(): string {
 + $principalUri = $this->data['principaluri'];
 + $principalUriParts = explode('/', $principalUri);
 + $user = end($principalUriParts);
 +        return $user;
 +    }
 +
 +    public function getDisplayName(): string {
 +        return $this->data['displayname'];
 +    }
 +
 +    public function __debugInfo(): array {
 +        // keeps print_r() useful
 +        return $this->data;
 +    }
 +}
 +
 +private function fetchCalendarById(int $calendarId) {
 + $query = $this->dbConnection->getQueryBuilder();
 + $query->select('*')
 + ->from('calendars')
 + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId, IQueryBuilder::PARAM_INT)));
 + $result = $query->executeQuery();
 + $calendar = $result->fetch();
 + $result->closeCursor();
 +
 + if (empty($calendar)) {
 + return false;
 + }
 +
 + return new Calendar($calendar);
 +}
 +</code>
 +
 +print and debug php database queries
 +
 +<code php>
 +$query->select('id', 'calendarid', 'firstoccurence')
 + ->from('calendarobjects')
 + ->where($filterQuery);
 +
 +printf("SQL: %s\n", $query->getSQL());
 +printf("Parameters: %s\n", print_r($query->getParameters(), true));
 +</code>
 +
 +check if array key exists (avoid undefined warning) via "null casting"
 +
 +<code php>
 +if ($config['listCalendars'] ?? false) {
 +</code>
 ==== nextcloud app dev ==== ==== nextcloud app dev ====
 logging, available methods: emergency, alert, critical, error, warning, notice, info, debug logging, available methods: emergency, alert, critical, error, warning, notice, info, debug
Line 567: Line 709:
 </code> </code>
  
 +logging
 +
 +<code php>
 +$this->logger->debug('Running actual SQL query {sql} with parameters {params}', [
 + 'sql' => $query->getSQL(),
 + 'params' => print_r($query->getParameters(), true),
 + 'app' => 'cleanup',
 +]);
 +</code>
 ==== wordpress ==== ==== wordpress ====
 registering menus registering menus
Line 709: Line 860:
 </code> </code>
  
-print setting text inside template +add custom javascript js
-<code php> +
-<?php echo get_option('fachwerksauna_footer-text'); ?> +
-</code>+
  
-customizer color chooser 
 <code php> <code php>
-function theme_customize_register$wp_customize ) { +function twentytwentytwo_enqueue_custom_js() { 
- +    wp_enqueue_script('custom', get_stylesheet_directory_uri().'/inc/js/main.js');
-    $wp_customize->add_setting( 'theme_color', array( +
-        'default'   => '#ed9b40', +
-        'transport' => 'refresh', +
-      ); +
- +
-    $wp_customize->add_control( new WP_Customize_Color_Control( +
-    $wp_customize, 'theme_color', array( +
-    'section' => 'colors', +
-    'label'   => esc_html__( 'Theme color', 'theme), +
-    ) ) ); +
- +
-}; +
- +
-function fachwerksauna_customize_css() +
-+
-    $theme_color = get_theme_mod('theme_color', '#ed9b40'); +
-    ?> +
-         <style type="text/css"> +
-             :root { +
-                --themeColor: <?php echo $theme_color; ?>; +
-            } +
-         </style> +
-    <?php+
 } }
  
-add_action( 'wp_head', 'fachwerksauna_customize_css');+add_action( 'wp_enqueue_scripts', 'twentytwentytwo_enqueue_custom_js' );
 </code> </code>
 ===== sql ===== ===== sql =====
-Update field: 
-<code sql> 
-update forwardings set destination='alex.bloss@online.de' where 'destination=bloss@bigwood.de'; 
-</code> 
-Insert field: 
-<code sql> 
-insert into forwardings (source, destination) VALUES ('markus.heim@wew-heim.de', 'heimmarkus@yahoo.de'); 
-insert into forwardings VALUES ('markus.heim@wew-heim.de', 'heimmarkus@yahoo.de'); 
-</code> 
-Delete row: 
-<code sql> 
-delete from domains where domain='alex-vt.de'; 
-</code> 
 <code sql> <code sql>
 mysql> \P /usr/bin/less mysql> \P /usr/bin/less
Line 778: Line 889:
 </code> </code>
  
-==== mysql ====+==== mariadb / mysql ====
  
-Dump database +select column and sort alphabetically
-<code bash> +
-mysqldump -u root -p Tutorials > tut_backup.sql +
-</code>+
  
-Backup everything 
-<code bash> 
-mysqldump -u root -p --all-databases > alldb.sql 
-</code> 
- 
-Import database 
 <code> <code>
-mysql> CREATE DATABASE wordpress; +SELECT user_id 
-sudo mysql -u root wordpress < wordpress.sql+FROM oc_user_oidc 
 +ORDER BY user_id ASC;
 </code> </code>
  
-Setup +delete specific row
-<code bash> +
-systemctl stop mysqld +
-mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql +
-systemctl start mysqld +
-mysql_secure_installation +
-</code>+
  
-delete specific row 
 <code> <code>
 delete from oc_storages where numeric_id=58; delete from oc_storages where numeric_id=58;
Line 810: Line 906:
  
 remove user remove user
 +
 <code sql> <code sql>
 DROP USER 'bloguser'@'localhost'; DROP USER 'bloguser'@'localhost';
 </code> </code>
  
-==== postgresql ====+adjust permissions to table
  
-drop database +<code sql
-<code bash+CREATE USER 'ninja'@'http.pi' IDENTIFIED BY '****'; 
-sudo -u postgres -i +GRANT ALL PRIVILEGES ON ninja.* TO 'ninja'@'http.pi' identified by '123'; 
-dropdb onlyoffice+GRANT ALL PRIVILEGES ON ninja.* TO 'ninja'@'http.pi'; 
 +FLUSH PRIVILEGES;
 </code> </code>
  
-list databases +update statement
-<code> +
-psql# \l +
-</code>+
  
-dump database +<code sql
-<code> +UPDATE wp_options SET option_value = 'info@example.org' WHERE option_name = 'admin_email';
-pg_dump -U gitlab gitlabhq_production > /tmp/gitlab.pgsql+
 </code> </code>
  
-dump all +sort column by timestamp and convert to datetime
-<code> +
-pg_dumpall > /tmp/dump_file_name.tar +
-</code>+
  
-import database +<code sql
-<code> +SELECT 
-psql# CREATE DATABASE gitlabhq_production; +    `id`, 
-psql -U gitlab gitlabhq_production gitlab.pgsql+    `calendarid`, 
 +    FROM_UNIXTIME(`firstoccurence`) AS firstoccurence, 
 +    FROM_UNIXTIME(`lastoccurence`)  AS lastoccurence 
 +FROM `oc_calendarobjects` 
 +WHERE (`lastoccurence` 1606694400) 
 +  AND (`firstoccurence` > 0) 
 +  AND (`componenttype` = 'VEVENT'
 +ORDER BY `lastoccurence` DESC;
 </code> </code>
  
-create and delete user +==== django ==== 
-<code> + 
-DROP ROLE gitlab; +admin, searchable dropdown. plan field will be searchable. 
-CREATE USER gitlab WITH PASSWORD '5V0hD0KWX81g5dhKGHsbqU4a';+ 
 +<code python
 +class GovernmentPlanUpdateAdmin(admin.ModelAdmin): 
 +    [...] 
 +    autocomplete_fields = ["plan"
 +     
 +[...] 
 + 
 +class GovernmentPlanAdmin(admin.ModelAdmin): 
 +    form = GovernmentPlanForm 
 +    [...] 
 +    search_fields = ("title",)
 </code> </code>
  
-grant permissions +===== nix ===== 
-<code> + 
-ALTER USER gitlab SUPERUSER; +====== lib ====== 
-CREATE DATABASE gitlabhq_production OWNER gitlab; + 
-ALTER DATABASE gitlabhq_production OWNER TO gitlab;+remove prefix 
 + 
 +<code nix
 +stripped = 
 +  lib.removePrefix "www." 
 +    (lib.removePrefix "https://" url);
 </code> </code>
onny/notizen/programmierung.1646933403.txt.gz · Last modified: by 185.52.247.41