Skip to content

Instantly share code, notes, and snippets.

@rolfen
rolfen / ADB_remote_wifi.md
Last active March 6, 2020 11:51
Remote (wifi) control your android device through ADB

You will need to connect your phone first, using USB.

With the USB cable:

adb tcpip 5555

Find out the IP address of your phone

@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 / MySqlExportBlob.md
Last active May 22, 2019 10:41
Exporting multiple blobs/images from an SQL database

Exporting multiple blobs from an SQL database.

This is tested for MySQL with Linux or OSX

I was in a situation where I had images saved into an SQL table, as "blobs" and needed to export them into proper jpg files.

This relies on the SQL syntax SELECT INTO DUMPFILE. However this command can only export one row at a time.

1. Get the IDs of the rows we want to export

Various commands

@rolfen
rolfen / EMAIL.md
Last active August 18, 2018 13:27
Setting up a Linux server
@rolfen
rolfen / ReadMe.md
Last active June 25, 2018 16:11
Get GPS coordinates for major cities
@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 / draggable.js
Last active December 4, 2017 09:27
Easy and lean drag-move functionality.
/**
* Minimal drag-move code.
* https://jsfiddle.net/rolfen/68bg5ggw/
*
* @param ele {HTMLElement} the container element to drag
* @param triggers {Array} One or more "drag triggers", areas (inside ele) that will trigger the drag functionality when clicked on.
* @param onDragStart {function} Called when dragging starts (trigger is grabbed)
* @param onDragEnd {function} Called when dragging ends (trigger is released)
*
* Issues:
@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 / 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);
}