Skip to content

Instantly share code, notes, and snippets.

View ahwayakchih's full-sized avatar
🏠
Working from home

Marcin Konicki ahwayakchih

🏠
Working from home
View GitHub Profile
@ahwayakchih
ahwayakchih / cp2bfs
Created April 21, 2021 10:18
Copy a single file or directory into BFS disk image
#!/bin/sh
# Simple script that mounts specified BFS disk image file to temporary directory,
# copies specified file there, unmounts the image and removes temporary directory.
# Usage: cp2bfs my-file-to-copy my-test-disk.bfs
MOUNTDIR=
FROM=$1
BFSFILE=$2
@ahwayakchih
ahwayakchih / nodebb-import-custom-pre-parse-conversion.js
Created February 17, 2021 17:47
Custom function for converting posts content from IPBoard to NodeBB using nodebb-plugin-import module
// Custom convert function for nodebb import plugin
content = content && encoding.convert(content, 'utf8', 'ISO-8859-2');
content = content && content.toString('utf8');
// This depends on changes implemented in https://github.com/ahwayakchih/nodebb-plugin-import/tree/feat-pass-type-and-id-to-custom-js
// It also assumes that HTML-to-Markdown conversion will be enabled too
// This is quite slow. Regexes probably could be optimized a bit, but it's a one-time-use-and-forget operation, so not much point i guess
if (type == 'post') {
content = content && content
.replace(/<!--quoteo\(post=(\d+)[^)]+name=([^):]+)[\w\W]+?<a\s+href="([^"]+)"[\w\W]+?<!--quotec-->([\w\W]+?)<!--QuoteEnd-->[\w\W]+?<!--QuoteEEnd-->/g, (m, pid, name, link, text) => {
@ahwayakchih
ahwayakchih / get_googles_ips.sh
Created April 23, 2020 08:06
Get IP4s of Google's servers' to, for example, whitelist them for accessing own services
#!/bin/sh -e
get_ip4s () {
dig +short txt $1 | grep -Eo '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/(3[0-2]|[1-2][0-9]|[1-9])?)?' | tr '\n' ','
}
echo -n $(get_ip4s _netblocks.google.com)
# `_netblocks2.google.com` returns only IPv6 addresses, so we can skip it
#echo -n $(get_ip4s _netblocks2.google.com)
echo -n $(get_ip4s _netblocks3.google.com)
@ahwayakchih
ahwayakchih / screenlock.sh
Created November 19, 2018 15:28
Lock screen on Linux with i3lock and Gnome 3
#!/bin/sh -e
if [ `ps -u $USER | grep -Ec "(i3lock|totem|mpv|vlc|*mplayer)"` -gt 0 ]; then
exit
fi
i3lock -c 333333 -i ~/Pictures/Wallpapers/screenlock.png -f;
function get_idle_time() {
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Mutter/IdleMonitor/Core --method org.gnome.Mutter.IdleMonitor.GetIdletime | sed -r 's/.*uint64 *([0-9]+).*/\1/g';
@ahwayakchih
ahwayakchih / pause_active_app.cpp
Created September 22, 2018 07:15
Proof-of-concept of quick pause/resume active application on Haiku
/*
* Copyright 2018, Marcin Konicki
* All rights reserved. Distributed under the terms of the MIT license.
*/
// This was written after reading:
// https://vermaden.wordpress.com/2018/09/19/freebsd-desktop-part-16-configuration-pause-any-application/
// and then:
// https://dev.haiku-os.org/ticket/14507
@ahwayakchih
ahwayakchih / Drupal Admin HTML Block
Last active October 2, 2017 13:44
Drupal - add "add", "edit" and "remove" buttons next to the autocomplete inputs of entityreference fields.
<!-- EXAMPLE of type information that will be used by "Add" buttons, if available:
<script type="application/json" id="entityreference-types">
{
"types": {
"blockquote": "Blockquote",
"custom-page": "Page",
"product": "Product",
"simple-picture": "Simple Picture"
},
"fields": {
@ahwayakchih
ahwayakchih / gist:3022618
Created June 30, 2012 06:17
Symphony-cms: IPR vs RPP timing
<?php
Class extension_improvedpageresolve extends Extension{
public function about() {
return array('name' => __('Improved Page Resolve'),
'version' => '1.2',
'release-date' => '2012-06-28',
'author' => array('name' => 'Marcin Konicki',
'website' => 'http://ahwayakchih.neoni.net',
@ahwayakchih
ahwayakchih / a-test-of-table-borders-slowdown-in-firefox.html
Created January 8, 2012 11:48
Test: Firefox slowdown on borders and floats.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Test of Firefox slowdown on borders and floats</title>
<style type="text/css">
body {
overflow: hidden;
padding: 0 30px 0 30px;
background: #444;
@ahwayakchih
ahwayakchih / test_permissions.php
Created July 8, 2011 18:55
PHP to find possible file and directory permissions to be used by Symphony CMS
<?php
/*
* This is just a test. Code could be written in much fewer lines :).
*/
function findPerms() {
$fstat = $dstat = array('uid' => 0, 'gid' => 0);
// Get information about newly created directory
if (!mkdir('test')) {
@ahwayakchih
ahwayakchih / test_datetime.php
Created July 6, 2011 11:51
Test PHP `DateTime(date())` vs `if(can call DateTime->setTimestamp) DateTime->setTimestamp() else DateTime(date())`
<?php
/*
* Test how calling `DateTime(date())` compares to checking for `DateTime::createFromFormat()`
* or `DateTime->setTimestamp()` and using `date()` as fallback only.
*
* Output should show something like:
*
* Using date() without any check: 4.3791408538818s
* Using DateTime::createFromFormat(): 5.6960089206696s