Skip to content

Instantly share code, notes, and snippets.

View pawlik's full-sized avatar
🎯
Focusing

Grzegorz Pawlik pawlik

🎯
Focusing
View GitHub Profile
@pawlik
pawlik / gist:4052010
Created November 10, 2012 18:20
heroku db:push
/home/greg/.rvm/gems/ruby-1.8.7-p358/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:211: [BUG] unknown type 0x22 (0xc given)
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0034 p:---- s:0153 b:0153 l:000152 d:000152 CFUNC :initialize
c:0033 p:---- s:0151 b:0151 l:000150 d:000150 CFUNC :new
c:0032 p:0089 s:0141 b:0141 l:000140 d:000140 METHOD /home/greg/.rvm/gems/ruby-1.8.7-p358/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:211
c:0031 p:0012 s:0134 b:0134 l:000768 d:000133 BLOCK /home/greg/.rvm/gems/ruby-1.8.7-p358/gems/sequel-3.20.0/lib/sequel/database/misc.rb:45
c:0030 p:---- s:0131 b:0131 l:000130 d:000130 FINISH
c:0029 p:---- s:0129 b:0129 l:000128 d:000128 CFUNC :call
@pawlik
pawlik / gist:4048819
Created November 9, 2012 22:45
fault spec migration test
# file extract_addresses_from_companies
load 'spec/spec_helper.rb'
load 'db/migrate/20121109212148_extract_addresses_from_companies.rb'
describe ExtractAddressesFromCompanies do
before do
@previous_migration_version = '20121108165838'
@my_migration_version = '20121109212148'
end
@pawlik
pawlik / gist:48cc4afba9d1523d4858
Last active August 29, 2015 14:19
Migration solution - PAIN to write, but compatibile by default

"Write safe migrations" approach.

This is what I've mentioned on our call. Let me prove this could work and please prove me wrong or point weak spots.

Assumptions

  • We can agree on how many steps we want to be able to rollback to (capistrano supports it, now on webstore is 2. I think increasing this too much makes no sense. Personally I think 2 is perfect - can't imagine that we release 1.19, after two weekes we release 1.20, after another 2 weeks 1.21 and at this point PO decides we want to rollback to version from a month ago).
  • don't think that database migrations is about just database migrations - it's also about writing code in a way it can handle this migrations.
  • future actions can be easily managed with something similar to roadsigns. For migrations, in case you need column to be removed in some unspecified future you can leave file CHECK_THIS_BEFORE_MAKING_NEW_MIGRATION, with entry 2015-01-12 prepared for column foo removal. Please remove after at least 5 releases (see first assumpti
@pawlik
pawlik / git-cache.sh
Created April 8, 2015 01:18
When full clone is too long - make a cache. You can run it with `watch -n 1 ./git-cache.sh git@github.com:Username/RepoName`, it will create cached version on /tmp/git-cache/git@github.com:Username/Reponame so you can clone new repos from there. Good when you make many clones and it's slow. Add apriopriate remotes when needed.
cache_dir="/tmp/git-cache/"
if [ ! -d "$cache_dir" ]
then
mkdir -p $cache_dir
fi
cache_path=$cache_dir$1
if [ ! -d "$cache_path" ]
then
git clone --mirror $1 $cache_path
else
@pawlik
pawlik / delegator.md
Last active August 29, 2015 14:17
Delegator

:trollface: 👍 👎 ✈️ 🎨 🐻 🍺 🚲 💣 📖

@pawlik
pawlik / mgnt-maintenance.go
Created February 13, 2015 14:06
cmd script to enable/disable maintenance mode in magento 1.*
package main
import (
"fmt"
io "io/ioutil"
"os"
"flag"
)
func usage() {
@pawlik
pawlik / gist:5189e75a4ccbd52fa589
Last active August 29, 2015 14:12
is ruby like tap possible in php even in ?
<?php
class Tappable {
private $whatever = null;
public function __construct($whatever) {
$this->whatever = $whatever;
}
public function tap(callable $callback) {
goal: give helper A possibility to inject 'tax helper', if none injected - Mage::helper('tax') should be used by default.
both ways work:
1)
```php
/**
* @var Mage_Tax_Helper_Data
*/
@pawlik
pawlik / gist:93b3d203d9a777916f65
Created September 15, 2014 14:38
Hex color game cheat

http://johnsythinks.com/hex/

Thanks to http://www.javascripter.net/faq/hextorgb.htm

function hexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function hexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function hexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}

this is my quick resolve function: