onny:notizen:programmierung
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| onny:notizen:programmierung [2022/03/08 11:26] – [wordpress] 46.223.163.98 | onny:notizen:programmierung [2026/09/08 12:09] (current) – [django] 10.250.0.1 | ||
|---|---|---|---|
| Line 56: | Line 56: | ||
| date = datetime.datetime.now().strftime(" | date = datetime.datetime.now().strftime(" | ||
| </ | </ | ||
| + | |||
| requests | requests | ||
| + | |||
| <code python> | <code python> | ||
| import requests | import requests | ||
| Line 66: | Line 68: | ||
| if (upstream_head.headers[' | if (upstream_head.headers[' | ||
| upstream_response = upstream_response.replace("// | upstream_response = upstream_response.replace("// | ||
| + | </ | ||
| + | |||
| + | class example | ||
| + | |||
| + | <code python> | ||
| + | class Planday: | ||
| + | auth_url = ' | ||
| + | client_id = ' | ||
| + | access_token = '' | ||
| + | |||
| + | def authenticate(self): | ||
| + | payload = { | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | } | ||
| + | headers = { | ||
| + | ' | ||
| + | } | ||
| + | session = requests.session() | ||
| + | session.trust_env = False | ||
| + | response = session.request(" | ||
| + | response = json.loads(response.text) | ||
| + | self.access_token = response[' | ||
| + | |||
| + | planday = Planday() | ||
| + | planday.authenticate() | ||
| </ | </ | ||
| ==== ponyorm ==== | ==== ponyorm ==== | ||
| Line 176: | Line 205: | ||
| </ | </ | ||
| ===== javascript ===== | ===== javascript ===== | ||
| + | |||
| + | conditional properties in object | ||
| + | <code javascript> | ||
| + | cont my_object = { | ||
| + | ...(version >= 33 ? { iconSvgInline: | ||
| + | } | ||
| + | </ | ||
| + | |||
| 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 || {})); | ||
| </ | </ | ||
| - | jquery select by attribute content | + | |
| - | <code javascript> | + | on document ready |
| - | $( " | + | |
| - | </ | + | |
| - | jquery select dynamicly loaded ajax elements | + | |
| <code javascript> | <code javascript> | ||
| - | $(' | + | document.addEventListener(" |
| - | | + | |
| - | load_page(link); | + | |
| }); | }); | ||
| + | |||
| </ | </ | ||
| - | jquery set background color | + | |
| - | <code javascript> | + | change content text |
| - | $(this).parent().css(" | + | |
| - | </ | + | |
| - | print mixed objects | + | |
| - | <code javascript> | + | |
| - | console.log(' | + | |
| - | </ | + | |
| - | javascript document ready | + | |
| - | <code javascript> | + | |
| - | $(document).ready(function(){ | + | |
| - | console.log(' | + | |
| - | }); | + | |
| - | </ | + | |
| - | vanilla js change content text | + | |
| <code javascript> | <code javascript> | ||
| var webgl_field = document.getElementById(' | var webgl_field = document.getElementById(' | ||
| Line 226: | Line 250: | ||
| } | } | ||
| </ | </ | ||
| - | vanilla js ajax post form | + | |
| + | ajax post form | ||
| <code javascript> | <code javascript> | ||
| document.getElementById(' | document.getElementById(' | ||
| Line 244: | Line 270: | ||
| } | } | ||
| </ | </ | ||
| - | 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, | var string = string.substring(0, | ||
| </ | </ | ||
| - | vanilla js onclick class element | + | onclick class element |
| <code javascript> | <code javascript> | ||
| document.getElementsByClassName(' | document.getElementsByClassName(' | ||
| console.log(' | console.log(' | ||
| }; | }; | ||
| + | </ | ||
| + | |||
| + | onclick on all class elements | ||
| + | |||
| + | <code javascript> | ||
| + | # old: var anchors = document.getElementsByClassName(' | ||
| + | let allCheckBox = document.querySelectorAll(' | ||
| + | |||
| + | allCheckBox.forEach((checkbox) => { | ||
| + | checkbox.addEventListener(' | ||
| + | if (event.target.checked) { | ||
| + | console.log(event.target.value) | ||
| + | } | ||
| + | }) | ||
| + | }) | ||
| + | </ | ||
| + | |||
| + | remove class from element | ||
| + | |||
| + | <code javascript> | ||
| + | var element = document.getElementsByClassName(' | ||
| + | element.classList.remove(" | ||
| + | </ | ||
| + | |||
| + | get url and pathname | ||
| + | |||
| + | <code javascript> | ||
| + | console.log(window.location.url) | ||
| + | console.log(window.location.pathname) | ||
| + | </ | ||
| + | |||
| + | querySelector, | ||
| + | |||
| + | <code javascript> | ||
| + | var h3 = document.querySelector(' | ||
| + | console.log(h3.textContent); | ||
| + | h3.querySelector(' | ||
| + | </ | ||
| + | |||
| + | querySelectorAll | ||
| + | |||
| + | <code javascript> | ||
| + | var productAccordion = document.querySelectorAll(' | ||
| + | productAccordion[1].style.display = " | ||
| + | </ | ||
| + | |||
| + | get next or previous element | ||
| + | |||
| + | <code javascript> | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| </ | </ | ||
| ==== vuejs ==== | ==== vuejs ==== | ||
| Line 440: | Line 521: | ||
| } | } | ||
| </ | </ | ||
| - | ===== css ===== | + | |
| - | sweet font styling | + | ===== php ===== |
| - | < | + | |
| - | font-family: consolas,Menlo-Regular, | + | printf string |
| - | font-size: 125%; | + | |
| - | line-height: | + | < |
| + | printf(" | ||
| </ | </ | ||
| - | media queries, page greater than 600px | + | |
| - | < | + | print array |
| - | | + | |
| - | article { | + | < |
| - | min-width: 600px; | + | $a = array (' |
| - | } | + | print_r($a); |
| - | } | + | |
| </ | </ | ||
| - | 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: | ||
| - | padding: 20px; | ||
| - | z-index: 2; | ||
| - | left: 17px; | ||
| - | background: | ||
| - | } | ||
| - | .main-navigation ul li:hover ul.sub-menu { | + | filter array only unique items |
| - | opacity: 1; | + | |
| - | transition: | + | <code php> |
| - | } | + | $userIds = array_unique($userIds); |
| </ | </ | ||
| - | responsive grid layout | + | append to array |
| - | < | + | |
| - | ul { | + | < |
| - | display: grid; | + | $fruits = [' |
| - | grid-gap: 50px 40px; | + | $fruits[] = ' |
| - | grid-template-columns: | + | |
| - | } | + | |
| </ | </ | ||
| - | ===== php ===== | + | |
| + | assosiative array / dictionary | ||
| + | |||
| + | <code php> | ||
| + | $myResult[" | ||
| + | </ | ||
| + | |||
| + | datetime object, convert to string | ||
| + | |||
| + | < | ||
| + | $date = new \DateTime(' | ||
| + | $dateString | ||
| + | </ | ||
| enable debugging / error log | enable debugging / error log | ||
| + | |||
| <file - / | <file - / | ||
| display_startup_errors = true | display_startup_errors = true | ||
| Line 496: | Line 577: | ||
| chmod a+w+r / | chmod a+w+r / | ||
| </ | </ | ||
| + | |||
| foreach loop | foreach loop | ||
| + | |||
| <code php> | <code php> | ||
| foreach($this-> | foreach($this-> | ||
| Line 506: | Line 589: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| 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(" | intval(" | ||
| Line 529: | Line 616: | ||
| </ | </ | ||
| + | |||
| + | define class, create object | ||
| + | |||
| + | <code php> | ||
| + | class Calendar { | ||
| + | private array $data; | ||
| + | |||
| + | public function __construct(array $data) { | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | public function getUserId(): | ||
| + | $principalUri = $this-> | ||
| + | $principalUriParts = explode('/', | ||
| + | $user = end($principalUriParts); | ||
| + | return $user; | ||
| + | } | ||
| + | |||
| + | public function getDisplayName(): | ||
| + | return $this-> | ||
| + | } | ||
| + | |||
| + | public function __debugInfo(): | ||
| + | // keeps print_r() useful | ||
| + | return $this-> | ||
| + | } | ||
| + | } | ||
| + | |||
| + | private function fetchCalendarById(int $calendarId) { | ||
| + | $query = $this-> | ||
| + | $query-> | ||
| + | -> | ||
| + | -> | ||
| + | $result = $query-> | ||
| + | $calendar = $result-> | ||
| + | $result-> | ||
| + | |||
| + | if (empty($calendar)) { | ||
| + | return false; | ||
| + | } | ||
| + | |||
| + | return new Calendar($calendar); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | print and debug php database queries | ||
| + | |||
| + | <code php> | ||
| + | $query-> | ||
| + | -> | ||
| + | -> | ||
| + | |||
| + | printf(" | ||
| + | printf(" | ||
| + | </ | ||
| + | |||
| + | check if array key exists (avoid undefined warning) via "null casting" | ||
| + | |||
| + | <code php> | ||
| + | if ($config[' | ||
| + | </ | ||
| ==== 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: | ||
| </ | </ | ||
| + | logging | ||
| + | |||
| + | <code php> | ||
| + | $this-> | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ]); | ||
| + | </ | ||
| ==== wordpress ==== | ==== wordpress ==== | ||
| registering menus | registering menus | ||
| Line 703: | Line 860: | ||
| </ | </ | ||
| - | print setting text inside template | + | add custom javascript js |
| <code php> | <code php> | ||
| - | <?php echo get_option('fachwerksauna_footer-text' | + | function twentytwentytwo_enqueue_custom_js() { |
| + | wp_enqueue_script(' | ||
| + | } | ||
| + | |||
| + | add_action( ' | ||
| </ | </ | ||
| ===== sql ===== | ===== sql ===== | ||
| - | Update field: | ||
| - | <code sql> | ||
| - | update forwardings set destination=' | ||
| - | </ | ||
| - | Insert field: | ||
| - | <code sql> | ||
| - | insert into forwardings (source, destination) VALUES (' | ||
| - | insert into forwardings VALUES (' | ||
| - | </ | ||
| - | Delete row: | ||
| - | <code sql> | ||
| - | delete from domains where domain=' | ||
| - | </ | ||
| <code sql> | <code sql> | ||
| mysql> \P / | mysql> \P / | ||
| Line 740: | Line 889: | ||
| </ | </ | ||
| - | ==== mysql ==== | + | ==== mariadb / mysql ==== |
| - | Dump database | + | select column and sort alphabetically |
| - | <code bash> | + | |
| - | mysqldump -u root -p Tutorials > tut_backup.sql | + | |
| - | </ | + | |
| - | Backup everything | ||
| - | <code bash> | ||
| - | mysqldump -u root -p --all-databases > alldb.sql | ||
| - | </ | ||
| - | |||
| - | Import database | ||
| < | < | ||
| - | mysql> CREATE DATABASE wordpress; | + | SELECT user_id |
| - | sudo mysql -u root wordpress < wordpress.sql | + | FROM oc_user_oidc |
| + | ORDER BY user_id ASC; | ||
| </ | </ | ||
| - | Setup | + | delete specific row |
| - | <code bash> | + | |
| - | systemctl stop mysqld | + | |
| - | mysql_install_db --user=mysql --basedir=/ | + | |
| - | systemctl start mysqld | + | |
| - | mysql_secure_installation | + | |
| - | </ | + | |
| - | delete specific row | ||
| < | < | ||
| delete from oc_storages where numeric_id=58; | delete from oc_storages where numeric_id=58; | ||
| Line 772: | Line 906: | ||
| remove user | remove user | ||
| + | |||
| <code sql> | <code sql> | ||
| DROP USER ' | DROP USER ' | ||
| </ | </ | ||
| - | ==== postgresql ==== | + | adjust permissions to table |
| - | drop database | + | < |
| - | < | + | CREATE USER ' |
| - | sudo -u postgres -i | + | GRANT ALL PRIVILEGES ON ninja.* TO ' |
| - | dropdb onlyoffice | + | GRANT ALL PRIVILEGES ON ninja.* TO ' |
| + | FLUSH PRIVILEGES; | ||
| </ | </ | ||
| - | list databases | + | update statement |
| - | < | + | |
| - | psql# \l | + | |
| - | </ | + | |
| - | dump database | + | < |
| - | < | + | UPDATE wp_options SET option_value = ' |
| - | pg_dump -U gitlab gitlabhq_production > /tmp/gitlab.pgsql | + | |
| </ | </ | ||
| - | dump all | + | sort column by timestamp and convert to datetime |
| - | < | + | |
| - | pg_dumpall > / | + | |
| - | </ | + | |
| - | import database | + | < |
| - | < | + | SELECT |
| - | psql# CREATE DATABASE gitlabhq_production; | + | |
| - | psql -U gitlab gitlabhq_production | + | `calendarid`, |
| + | FROM_UNIXTIME(`firstoccurence`) AS firstoccurence, | ||
| + | FROM_UNIXTIME(`lastoccurence`) | ||
| + | FROM `oc_calendarobjects` | ||
| + | WHERE (`lastoccurence` | ||
| + | AND (`firstoccurence` > 0) | ||
| + | AND (`componenttype` = ' | ||
| + | ORDER BY `lastoccurence` DESC; | ||
| </ | </ | ||
| - | create and delete user | + | ==== django ==== |
| - | < | + | |
| - | DROP ROLE gitlab; | + | admin, searchable dropdown. plan field will be searchable. |
| - | CREATE USER gitlab WITH PASSWORD ' | + | |
| + | < | ||
| + | class GovernmentPlanUpdateAdmin(admin.ModelAdmin): | ||
| + | [...] | ||
| + | autocomplete_fields = [" | ||
| + | |||
| + | [...] | ||
| + | |||
| + | class GovernmentPlanAdmin(admin.ModelAdmin): | ||
| + | form = GovernmentPlanForm | ||
| + | [...] | ||
| + | | ||
| </ | </ | ||
| - | grant permissions | + | ===== nix ===== |
| - | < | + | |
| - | ALTER USER gitlab SUPERUSER; | + | ====== lib ====== |
| - | CREATE DATABASE gitlabhq_production OWNER gitlab; | + | |
| - | ALTER DATABASE gitlabhq_production OWNER TO gitlab; | + | remove prefix |
| + | |||
| + | < | ||
| + | stripped = | ||
| + | | ||
| + | | ||
| </ | </ | ||
onny/notizen/programmierung.1646738762.txt.gz · Last modified: by 46.223.163.98
