Skip to content

Instantly share code, notes, and snippets.

View mt3o's full-sized avatar

Teodor Kulej mt3o

View GitHub Profile
#Here's some sample code based on the book Learning Python by Mark Lutz that addresses your question:
import sys
temp = sys.stdout # store original stdout object for later
sys.stdout = open('log.txt', 'w') # redirect all prints to this log file
print("testing123") # nothing appears at interactive prompt
print("another line") # again nothing appears. it's written to log file instead
sys.stdout.close() # ordinary file object
sys.stdout = temp # restore print commands to interactive prompt
print("back to normal") # this shows up in the interactive prompt
@mt3o
mt3o / echo-module.php
Created May 10, 2019 18:41
Echo joomla modules with php
<?php
// https://joomla.stackexchange.com/questions/1054/displaying-a-joomla-module-using-php
$modules = JModuleHelper::getModules("dashboard_main");
$document = JFactory::getDocument();
$attribs = array();
$attribs['style'] = 'xhtml';
foreach ($modules as $mod)
public class PooledObjectPool {
private static long expTime = 6000;//6 seconds
public static HashMap<PooledObject, Long> available = new HashMap<PooledObject, Long>();
public static HashMap<PooledObject, Long> inUse = new HashMap<PooledObject, Long>();
public synchronized static PooledObject getObject() {
long now = System.currentTimeMillis();
if (!available.isEmpty()) {
for (Map.Entry<PooledObject, Long> entry : available.entrySet()) {
@mt3o
mt3o / setup-linux.sh
Created June 13, 2017 13:28 — forked from arosini/setup-linux.sh
Sets up a new Linux installation
#!/bin/bash
##################
# Initialization #
##################
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install curl
##########
@mt3o
mt3o / template_hierarchy_debug.php
Created December 29, 2015 15:31
Print current wordpress template hierarchy.
<?php
/**
* Show template hierarchy and theme at the end of the request/page.
* @return void
*/
function wpse31909_template_info()
{
// Don't display for non-admin users
if ( ! current_user_can( 'manage_options' ) )
return;
@mt3o
mt3o / list.txt
Created November 27, 2015 09:54
pakieciki
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===========================================================-===================================================-============-=====================================================================================================================
ii accountsservice 0.6.35-0ubuntu7.2 amd64 query and manipulate user account information
ii acl 2.2.52-1 amd64 Access control list utilities
ii acpi-support 0.142 amd64
<?php
// do pobrania z https://code.google.com/p/phpquery/
// do pobrania z rashell.pl/clearsense/phpQuery-onefile.phps
require 'phpQuery-onefile.php';
$server = 'http://rashell.pl';
$results=array();
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) {
document.write("<meta name='viewport' content='width=1165, user-scalable=no'>"); // or whichever meta tags make sense for your site
} else {
document.write("<meta name='viewport' content='width=max-device-width, user- scalable=no'>"); // again, which ever meta tags you need
}
@mt3o
mt3o / gist:e0d7cf92377a2c892381
Created September 8, 2015 08:22
api do mydevil po sockecie
10:14 < krisd> mt3o: w python mozesz uzyc np. paramiko do laczenia sie przez ssh i wykonywania komend
10:15 <@samu> i socket może odpowiadać albo jsonem, albo picklem
10:17 <@samu> mt3o: $ echo '["--json", "www", "list"]' |nc -U /var/run/devil2.sock
10:17 < krisd> samu: masz jakies przyklady jak uzywac tego socketu?
10:17 <@samu> przykładów nie mam
10:17 <@samu> zwykłe połączenie z socketem na /var/run/devil2.sock
10:17 < mt3o> samu: to chyba wystarczy, thx :-)
10:17 < krisd> ok
10:17 <@samu> wysyłasz stringa, który jest prawidłową pythonową listą
10:17 <@samu> składającą się z tego, co byś wysyłał jako klient cli
@mt3o
mt3o / async-fonts.php
Created July 29, 2015 19:19
Load google and awesome fonts asynchronously, without blocking rendering
<?php foreach ([
'http://fonts.googleapis.com/css?family=Alegreya+SC&subset=latin,latin-ext',
'http://fonts.googleapis.com/css?family=Lora&subset=latin,latin-ext',
'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'
] as $font){
?>
<link
rel="stylesheet"
href="<?=$font?>"