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/07 13:26] – [wordpress] 141.52.248.2onny: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(){
   console.log('ready');   console.log('ready');
 }; };
 +</code>
 +
 +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>
 +document.getElementById('foo2').nextSibling; // #foo3
 +document.getElementById('foo2').previousSibling; // #foo1
 </code> </code>
 ==== vuejs ==== ==== vuejs ====
Line 440: 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 496: 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 506: Line 589:
 } }
 </code> </code>
 +
 get array length get array length
 +
 <code php> <code php>
 var_dump(count($a)); var_dump(count($a));
Line 512: Line 597:
  
 get type of variable get type of variable
 +
 <code php> <code php>
 foreach($data as $episode) { foreach($data as $episode) {
Line 519: Line 605:
  
 convert string to int convert string to int
 +
 <code php> <code php>
 intval("12345"); intval("12345");
Line 529: 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 561: 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 616: Line 773:
 } }
 </code> </code>
-===== sql ===== + 
-Update field+custom menu walker, only printing <a> tags without list items 
-<code sql+<code php> 
-update forwardings set destination='alex.bloss@online.dewhere 'destination=bloss@bigwood.de';+class Nav_Footer_Walker extends Walker_Nav_Menu { 
 + 
 +    function start_lvl( &$output, $depth 0, $args array() ) { 
 +        $indent str_repeat("\t", $depth); 
 +        $output ."\n$indent\n"; 
 +    } 
 + 
 +    function end_lvl( &$output, $depth 0, $args array() ) { 
 +        $indent str_repeat("\t", $depth); 
 +        $output ."$indent\n"; 
 +    } 
 + 
 +    function start_el( &$output, $item, $depth 0, $args array(), $id = 0 ) { 
 +        $indent = ( $depth ) ? str_repeat( "\t", $depth ) ''; 
 + 
 +        $class_names = $value = ''; 
 + 
 +        $classes = empty( $item->classes ) ? array() : (array) $item->classes; 
 +        $classes[] = 'menu-item-' . $item->ID; 
 + 
 +        $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) ); 
 +        $class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : ''; 
 + 
 +        $id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args ); 
 +        $id = $id ? ' id="' . esc_attr( $id ) . '"' : ''; 
 + 
 +        $output .= $indent . ''; 
 + 
 +        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : ''; 
 +        $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : ''; 
 +        $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : ''; 
 +        $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : ''; 
 + 
 +        $item_output = $args->before; 
 +        $item_output .= '<a class="navbar-item" '. $attributes .'>'; 
 +        $item_output .$args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) $args->link_after; 
 +        $item_output .'</a>'
 +        $item_output .$args->after; 
 + 
 +        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); 
 +    } 
 + 
 + 
 +    function end_el( &$output, $item, $depth = 0, $args = array() ) { 
 +        $output .= "\n"; 
 +    } 
 + 
 +
 + 
 +wp_nav_menu( array( 
 +    'menu'            => 'primary', 
 +    'container_id'    => 'mainNavbar', 
 +    'container_class' => 'navbar-menu', 
 +    'items_wrap'      => '<div class="navbar-end">%3$s</div>', 
 +    'walker'          => new Nav_Footer_Walker(), 
 +) );
 </code> </code>
-Insert field: + 
-<code sql+customizer add option custom text 
-insert into forwardings (source, destinationVALUES ('markus.heim@wew-heim.de', 'heimmarkus@yahoo.de'); +<code php
-insert into forwardings VALUES ('markus.heim@wew-heim.de', 'heimmarkus@yahoo.de');+function theme_customize_register$wp_customize 
 + 
 +    $wp_customize->add_setting( 'fachwerksauna_footer-text', array( 
 +        'default=> '', 
 +        'type' => 'option', 
 +        'capability' => 'edit_theme_options' 
 +    ),); 
 + 
 +    $wp_customize->add_controlnew WP_Customize_Control( 
 +        $wp_customize, 'footer-text_control', array( 
 +            'label'      => __( 'Footer text', 'fachwerksauna' ), 
 +            'description' => __( 'Text in footer area', 'fachwerksauna' ), 
 +            'settings'   => 'fachwerksauna_footer-text', 
 +            'priority'   => 10, 
 +            'section'    => 'title_tagline', 
 +            'type'       => 'text', 
 +        ) 
 +    ) ); 
 + 
 +
 + 
 +add_action( 'customize_register', 'theme_customize_register' );
 </code> </code>
-Delete row: + 
-<code sql+add custom javascript js 
-delete from domains where domain='alex-vt.de';+ 
 +<code php
 +function twentytwentytwo_enqueue_custom_js() { 
 +    wp_enqueue_script('custom', get_stylesheet_directory_uri().'/inc/js/main.js'); 
 +
 + 
 +add_action( 'wp_enqueue_scripts', 'twentytwentytwo_enqueue_custom_js' );
 </code> </code>
 +===== sql =====
 <code sql> <code sql>
 mysql> \P /usr/bin/less mysql> \P /usr/bin/less
Line 649: 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 681: 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.1646659568.txt.gz · Last modified: by 141.52.248.2 · Currently locked by: 10.250.0.1