Skip to content

Instantly share code, notes, and snippets.

View jkaflik's full-sized avatar

Kuba Kaflik jkaflik

View GitHub Profile
@jkaflik
jkaflik / hyperloglog_test.go
Created May 24, 2018 12:38
HyperLogLog test
package main
import (
"fmt"
"strconv"
"github.com/axiomhq/hyperloglog"
"github.com/c2h5oh/datasize"
)
@jkaflik
jkaflik / TB503A2.cpp
Created December 30, 2015 13:00
TB503A2 driver module example
//motor A connected between A01 and A02
//motor B connected between B01 and B02
int STBY = 10; //standby
//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction
@jkaflik
jkaflik / fibonacci.php
Created November 15, 2013 11:00
Benchmark for PHP vs HHVM
<?php
$start = microtime(true);
$first = 0;
$second = 1;
$n = 10000000;
for($i=1;$i<=$n-1;$i++)
{
@jkaflik
jkaflik / csv_splitter
Created September 18, 2013 09:24
CSV files splitter <kofels@gmail.com> usage: csv_splitter file file1 file2 options: -l=NUMBER_OF_ROWS specify num of rows per part, defaults 1000 -h print help -o=DIR output directory, by default the same as the original file -f files has headers (first row goes to each part of file)
#!/usr/bin/env php
<?php
/**
* CSV files splitter
* @author kofels@gmail.com
*/
// helpers functions
$stderr = function ($message) {
@jkaflik
jkaflik / core.js
Created June 13, 2013 09:44
Userscript which download suggested keywords according to your keywords array. It uses https://adwords.google.com/o/Targeting Usage: Open https://adwords.google.com/o/Targeting , run core.js script, and then run.js (first or second version)
var jq = document.createElement('script');jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js";document.getElementsByTagName('head')[0].appendChild(jq);
// Returns interval between next keywords suggestions download
// return value must be seconds (int)
// defaults: 15-30 seconds
var phraseInterval = function(){
return ( Math.random + 1 ) * 15;
};
var suggestedKeywordsOffset = 0;
<?php
$configString = 'opcja1 wartość;
opcja2 wartość;
blok1 {
opcja3 wartość;
opcja4 wartość;
blok1.1 {
opcja5 wartość;
@jkaflik
jkaflik / magento_fix_stock_items.sql
Created May 27, 2013 09:54
Fix for "Stock item for Product is not valid" error in Magento 1.x. It reproduces cataloginventory_stock_item using product entities.
INSERT INTO `cataloginventory_stock_item` (
`item_id` ,
`product_id` ,
`stock_id` ,
`qty` ,
`min_qty` ,
`use_config_min_qty` ,
`is_qty_decimal` ,
`backorders` ,
`use_config_backorders` ,
@jkaflik
jkaflik / gist:5445692
Created April 23, 2013 17:35
PHP ~ calculating thumbnail dimensions
<?php
function calculateThumbnailDimensions( $dim, $max )
{
$more = max( $dim );
$more_max = $max[ end( array_keys($dim, $more) ) ];
$scale = $more_max / $more;
@jkaflik
jkaflik / mergecsv.php
Created April 8, 2013 14:41
Easily merge .csv files which have an header
<?php
$options = array();
$arguments = array();
array_shift( $argv );
foreach ( $argv as $arg )
{
if ( $arg[0] == '-' )
@jkaflik
jkaflik / robot.js
Created December 4, 2012 22:04
NaOkoło
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
var takeDir = false
var haveTurn = true;