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 / mutex.php
Created June 23, 2011 18:03
Test new implementation of Mutex class for Symphony CMS
<?php
/*
* Just upload it to root directory of Symphony CMS installation and access it through web browser, e.g.,
* http://www.example.com/mutex.php
*
* It should output text like:
*
* Try: http://www.example.com/mutex.php?mode=block
* Blocking: Acquired
@ahwayakchih
ahwayakchih / func-vs-var.php
Created June 24, 2011 12:54
Test PHP's function call vs direct access to public static variable
<?php
/*
* Test how function calls compare to direct variable access for simple things
* like switching some flag/option.
*
* Output should show something like:
*
* Direct access took: 0.14991188049316s
* Function call took: 0.55304503440857s
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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)