Skip to content

Instantly share code, notes, and snippets.

☀️
hablo programación

Przemek Sobstel sobstel

☀️
hablo programación
Block or report user

Report or block sobstel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sobstel
sobstel / EnumType.php
Created Dec 13, 2010
Doctrine2 EnumType
View EnumType.php
<?php
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
/**
* My custom datatype.
*/
class EnumType extends Type
{
const ENUM = 'enum';
View Doctrine_Hydrator_FlatArray.class.php
<?php
/**
* Doctrine::HYDRATE_SCALAR without component alias at the beginning.
* For key names it takes columns and aliases from SELECT statement.
* First column/alias from statement is used as key for whole row.
*/
class Doctrine_Hydrator_FlatArray extends Doctrine_Hydrator_ScalarDriver {
public function hydrateResultSet($stmt)
{
@sobstel
sobstel / jQuery.fn.whenLoaded.js
Created Jan 21, 2011
jQuery onload event for images
View jQuery.fn.whenLoaded.js
jQuery.fn.whenLoaded = function(fn){
return this.each(function(){
// if already loaded call callback
if (this.complete || this.readyState == 'complete'){
fn.call(this);
} else { // otherwise bind onload event
$(this).load(fn);
}
});
}
@sobstel
sobstel / will_paginate_in_rails3.example.rb
Created Jan 21, 2011
will_paginate query with per_page working in rails3
View will_paginate_in_rails3.example.rb
@articles = Article.
select('articles.*, (SUM(votes.vote = 1)/COUNT(votes.vote)) votes_ratio, COUNT(votes.vote) votes_num').
joins(:votes).
group('articles.id').
having('votes_num >= 5 AND votes_ratio >= 0.8').
order('votes_ratio DESC, votes_num DESC').
paginate(:page => params[:page], :per_page => Article.per_page)
@sobstel
sobstel / function_in_method.php
Created Jan 28, 2011
PHP: function in method
View function_in_method.php
<?php
class FooClass {
public function foo_method() {
function foo_func() {
echo "it works, really";
}
}
}
$foo = new FooClass;
@sobstel
sobstel / lazy_assignment.as
Created Feb 2, 2011
Lazy assignment pattern
View lazy_assignment.as
var i:int = 0, l:int = points.length;
while (i < l) {
i+=1;
}
@sobstel
sobstel / hirb&wirble.rb
Created Feb 10, 2011
hirb and wirble configuration
View hirb&wirble.rb
# Source: http://sinatra.inf.ug.edu.pl/rails4/konfiguracja
# File: ~/.irbc
require 'rubygems'
require 'wirble'
require 'hirb'
Wirble.init
Wirble.colorize
Hirb.enable
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
require 'logger'
@sobstel
sobstel / interpret_status.rails3.rb
Created Feb 19, 2011
interpret_status in rails3
View interpret_status.rails3.rb
def interpret_status(status)
Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
end
@sobstel
sobstel / config
Created Mar 4, 2011
~/.mplayer/config (polish font in mplayer)
View config
fontconfig=yes
subcp=cp1250
subfont-text-scale=4
@sobstel
sobstel / comment.rb
Created Mar 11, 2011
mongoid: embedded document without object_id
View comment.rb
class Comment
include Mongoid::Document
field :name
# do not generate object_id
# for mongoid <=2.0rc7 (in newer mongoid use Mongoid.embedded_object_id = false)
def identify
end
You can’t perform that action at this time.