Skip to content

Instantly share code, notes, and snippets.

Avatar

Jan Ptacek ptica

View GitHub Profile
View scrape-paginated.php
require 'vendor/autoload.php';
function scrape_details($dom, &$details) {
$images = $dom->querySelector('.images');
foreach ($images->querySelectorAll('.pic') as $i => $e) {
$details[] = $e->getAttribute('href');
}
}
@ptica
ptica / install_oci8_ubuntu_16.04_php7.1.md
Last active Jul 19, 2018 — forked from hewerthomn/install_oci8_ubuntu_16.04_php7.1.md
How to install OCI8 on Ubuntu 16.04 and PHP 7.1
View install_oci8_ubuntu_16.04_php7.1.md
View gist:61243602cc3f56bb3be0
# index.html
<body>
<div id="jumbotron">
<h1>Hello, world!</h1>
<p>...</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a></p>
</div>
<div id="some">Some other content</div>
<body>
@ptica
ptica / gist:fbf0ec6bb7137bdfdbb8
Last active Aug 29, 2015
giant legacy users table -> limit app queries to work only with users that have roles recognised by the app
View gist:fbf0ec6bb7137bdfdbb8
select * from
(select
distinct "user_id"
from "roles_users"
) "my_users"
join "users"
on "my_users"."user_id" = "users"."id";
View gist:e3fe8e1937fef379b251
require_once(ROOT . DS . APP_DIR . '/Vendor/zordius/lightncandy/src/lightncandy.php');
$path = preg_replace('/\.ctp$/', '.hbs', __FILE__);
$template = file_get_contents($path);
$phpStr = LightnCandy::compile($template);
$renderer = LightnCandy::prepare($phpStr);
echo $renderer($data);
View node-and-npm-in-30-seconds.sh
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
#curl https://www.npmjs.org/install.sh | sh
#npm install commented out as it may result in SSL: certificate subject name 'a.sni.fastly.net'npm ..
@ptica
ptica / gist:3424300
Created Aug 22, 2012
cakephp 2.2.1 Model::save doubles all numeric arrays
View gist:3424300
function testDoubleSave() {
$to_save = array(
'Article' => array(
'title' => 'title',
'body' => 'body',
),
'Meta' => array(10, 12),
);
$result = $this->Article->save($to_save);
$expected = $to_save;
View schema_fragment.php
function after($event = array()) {
// on MYSQL: retype columns to mediumtext, as we store whole api response
// that is longer than std 64kB of mysql text
if (isset($event['create']) && $event['create'] == 'saved_queries') {
$db = &ConnectionManager::getDataSource($this->connection);
$sql = 'alter table saved_queries modify content mediumtext';
if (substr($db->config['driver'], 0, 5) == 'mysql') $db->execute($sql);
}
if (isset($event['create']) && $event['create'] == 'contracts') {
$db = &ConnectionManager::getDataSource($this->connection);
@ptica
ptica / mantos.pl
Created Sep 17, 2011
aggregate for mantos
View mantos.pl
#!/usr/bin/env perl
$encoding = 'cp1250';
open FILE, "<:encoding($encoding)", "mantos.csv" or die $!;
open RESULT, ">:encoding($encoding)", "result.csv" or die $!;
my %aggregates = ();
foreach my $line (<FILE>) {
# get rid of newlines and other whitespace
@ptica
ptica / idos.js
Created Apr 14, 2011
get the connection you want from idos.cz
View idos.js
var repl = require('repl');
var cli = repl.start();
var tt = {
from: "Praha",
to: "Brno"
date: "14.3.2010",
time: "6:00",
}