Skip to content

Instantly share code, notes, and snippets.

@giventofly
giventofly / cookies.js
Created May 4, 2022 22:19
javascript cookies
//src: https://www.quirksmode.org/js/cookies.html
const createCookie = (name,value,days)=> {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
@giventofly
giventofly / citrix.md
Created May 2, 2022 13:51
citrix linux error quovadis root ca 2 g3 ssl error 61 linux
@giventofly
giventofly / debounce.js
Created March 17, 2022 21:07
debounce javascript
//search decks
document.getElementById("decktosearch").addEventListener("keyup", debounceSearchDeck);
const debounce = (callback, wait) => {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback.apply(null, args);
@giventofly
giventofly / truncateString.js
Created March 1, 2022 10:37
truncate string max chars
//https://stackoverflow.com/a/44821227/10829833
function truncateString(text, count, insertDots){
return text.slice(0, count) + (((text.length > count) && insertDots) ? "..." : "");
}
@giventofly
giventofly / truncate.php
Created November 5, 2021 12:29
php truncate number
<?php
//https://stackoverflow.com/questions/4668628/truncate-float-numbers-with-php/12710283#12710283
function truncate($val, $f="2"){
if(($p = strpos($val, '.')) !== false) {
$val = floatval(substr($val, 0, $p + 1 + $f));
}
return $val;
}
@giventofly
giventofly / mouse ubuntu bluetooth lag.md
Created October 12, 2021 09:08
mouse ubuntu bluetooth mx master 3
sudo nano /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/yy:yy:yy:yy:yy:yy/info
[ConnectionParameters]
MinInterval=6
MaxInterval=7
Latency=0
Timeout=216
@giventofly
giventofly / gist:6ef71d1aaf846a509a28d706d8d5ef00
Created August 13, 2021 13:41
function keys fn keys linux
google for ibus
@giventofly
giventofly / safari_fix_100vh.css
Created June 15, 2021 10:16
Safari 15 viewheight height 100vh fix
//from https://lukechannings.com/blog/2021-06-09-does-safari-15-fix-the-vh-bug/
height:calc(100vh - env(safe-area-inset-bottom));
@giventofly
giventofly / import json google sheets.js
Created May 20, 2021 12:45
import json google sheets
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@giventofly
giventofly / add_items_menu_wp.php
Created May 12, 2021 20:10
wordpress add items to menu programatically
<?php
//add items to menu
add_filter( 'wp_nav_menu_items', 'add_extra_item_to_nav_menu', 10, 2 );
function add_extra_item_to_nav_menu( $items, $args ) {
if (is_user_logged_in() && $args->menu == 1357) {
$items .= '<li><a href="'. get_permalink( get_option('woocommerce_myaccount_page_id') ) .'">My Account</a></li>';
}
elseif (!is_user_logged_in() && $args->menu == 1357) {
$items .= '<li><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Sign in / Register</a></li>';