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 / conv_base16_to_base36.sql
Created May 17, 2014
Converting from base-16 to base-36 number (with 128bit precision)
View conv_base16_to_base36.sql
-- convert from base-16 to base-36 (128bit precision)
CREATE FUNCTION conv(_hex TEXT)
RETURNS TEXT
BEGIN
DECLARE _hex_len TINYINT;
DECLARE _dec DECIMAL(65);
DECLARE _chars CHAR(36);
DECLARE _base36 TEXT;
DECLARE _mod TINYINT;
@sobstel
sobstel / nginx-php-fpm.conf
Last active Aug 29, 2015
Nginx PHP common configuration
View nginx-php-fpm.conf
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^.+\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
@sobstel
sobstel / ssh_tunnel.sh
Created Feb 24, 2015
Connecting to remote server local services via SSH tunnel
View ssh_tunnel.sh
# SSH tunnel, so it's possible to connect to remote server services via SSH
# argument: local_port, dest_port, host
ssh_tunnel () {
lsof -i:$1 > /dev/null 2>&1 || ssh -fNg -L $1:127.0.0.1:$2 $3
}
# sample: mysql
ssh_tunnel 3307 3306 HOST
@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'
You can’t perform that action at this time.