Skip to content

Instantly share code, notes, and snippets.

View ptica's full-sized avatar

Jan Ptacek ptica

View GitHub Profile
@ptica
ptica / idos.js
Created April 14, 2011 18:00
get the connection you want from idos.cz
var repl = require('repl');
var cli = repl.start();
var tt = {
from: "Praha",
to: "Brno"
date: "14.3.2010",
time: "6:00",
}
@ptica
ptica / mantos.pl
Created September 17, 2011 13:16
aggregate for mantos
#!/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
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 / gist:3424300
Created August 22, 2012 10:46
cakephp 2.2.1 Model::save doubles all numeric arrays
function testDoubleSave() {
$to_save = array(
'Article' => array(
'title' => 'title',
'body' => 'body',
),
'Meta' => array(10, 12),
);
$result = $this->Article->save($to_save);
$expected = $to_save;
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 ..
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);
@ptica
ptica / gist:fbf0ec6bb7137bdfdbb8
Last active August 29, 2015 14:10
giant legacy users table -> limit app queries to work only with users that have roles recognised by the app
select * from
(select
distinct "user_id"
from "roles_users"
) "my_users"
join "users"
on "my_users"."user_id" = "users"."id";
# 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 / install_oci8_ubuntu_16.04_php7.1.md
Last active July 19, 2018 14:24 — forked from hewerthomn/install_oci8_ubuntu_16.04_php7.1.md
How to install OCI8 on Ubuntu 16.04 and PHP 7.1
require 'vendor/autoload.php';
function scrape_details($dom, &$details) {
$images = $dom->querySelector('.images');
foreach ($images->querySelectorAll('.pic') as $i => $e) {
$details[] = $e->getAttribute('href');
}
}