Skip to content

Instantly share code, notes, and snippets.

@rolfen
rolfen / 00 Ideas and notes
Last active August 24, 2023 23:45
Ideas and notes
Related to Linux
@rolfen
rolfen / gist:c57e4606856f900c654fabb5cf9a34b6
Last active February 20, 2018 15:42
Weston dropdown positioning bug
Sometimes drop-down or contextual menus appear at the wrong position on the screen.
Upon moving the parent window, it appears that the menu position is not updated. They still appear at the same position.
To reproduce with affected applications, open app, open drop-down menu, move app window, open same drowpdown menu - observe that the menu has not moved with the window and is subsequently now appearing at a wrong position.
If the window is resized, the menus get re-aligned.
Weston 3.0.0
(running in DRM mode)
There is such a bug in sway too. But over there it seems to affect everything (pcmanfm, lxterminal, subl, chromium...)
@rolfen
rolfen / ReadMe.md
Last active June 25, 2018 16:11
Get GPS coordinates for major cities
@rolfen
rolfen / funcs.php
Last active July 26, 2023 00:21
A library of utility of generally useful PHP functions (filesystem, images, ini, text manipulation...). Outdated version of PHP.
<?php
// ============ strings ================
function smart_truncate($string, $limit, $break=" ", $pad="...") {
// truncates string to the first $break after $limit characters, then adds $pad to the end
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
// return with no change if string is shorter than $limit
$string = strip_tags($string);
@rolfen
rolfen / detectArabic.js
Last active June 13, 2019 10:15
Detects whether a string is (mostly) Arabic (or Farsi, etc.)
/*
* Tries to detects whether a given string is "Arabic" (or Farsi, Pashto, etc.)
* The detection is based on counting "Arabic alphabet" characters
* Returns true if the string is mostly made of "Arabic characters", false otherwise
* This is how to use on HTML element "el":
* detectArabic(el.innerText)
*/
function detectArabic(string) {
try {
@rolfen
rolfen / ajaxListener.js
Last active October 10, 2017 15:15 — forked from icodejs/ajaxListener.js
JS: Listen to ajax calls from Javascript
// override XMLHttpRequest
// source: https://gist.github.com/icodejs/3183154
var open = window.XMLHttpRequest.prototype.open,
send = window.XMLHttpRequest.prototype.send;
function openReplacement(method, url, async, user, password) {
return open.apply(this, arguments);
}
@rolfen
rolfen / css.whatswrong.txt
Last active October 31, 2017 09:37
What's wrong with CSS
- Side effects (usually unwanted)
- Sometimes impractical: eg: vertical-align
- Sometimes too high level / opinionated and inflexible (related to all of above)
- Cascading - most of the inhertiance is unwanted
- Global-variable-like issues
- Overriding
__Improvements
I think it would be an important improvement, to be able to compound CSS blocks. A bit like less mixins, but at a native level. At the moment, if we are not using a pre-processor, we have to add multiple classes on elements (eg: <div class="col-2 pad-1 size-3">). That is neither powerful nor semantic.
@rolfen
rolfen / html.js
Created August 20, 2017 12:13
Lean function to generate html from JavaScript and do some of the nice things that React allows.
/**
* Generates html element based on a d-structure
* d-structure is:
* [ string tagname | HtmlElement root_element,
* object attributes,
* [child] | string text,
* funcion callback(el)
* ]
* child is:
* d-structure | string text | HtmlElement element
@rolfen
rolfen / parseForm.js
Last active June 27, 2017 19:45
Serialize form to JSON - the simple way
// credit: https://codepen.io/gabrieleromanato/pen/LpLVeQ
function parseInputs( elements ) {
var obj = {};
for( var i = 0; i < elements.length; ++i ) {
var element = elements[i];
var name = element.name;
var value = element.value;
if( name ) {
@rolfen
rolfen / ie_hacks.css
Last active December 8, 2016 14:25
IE CSS hacks
/* Source:
http://stackoverflow.com/a/30743013/370786
*/
/***** Attribute Hacks ******/
/* IE6 */
#once { _color: blue }
/* IE6, IE7 */