Skip to content

Instantly share code, notes, and snippets.

View sobstel's full-sized avatar

Przemek Sobstel sobstel

View GitHub Profile
@sobstel
sobstel / config
Created March 4, 2011 20:17
~/.mplayer/config (polish font in mplayer)
fontconfig=yes
subcp=cp1250
subfont-text-scale=4
@sobstel
sobstel / comment.rb
Created March 11, 2011 16:54
mongoid: embedded document without object_id
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
@sobstel
sobstel / clipped_text.css
Created March 18, 2011 17:18
Clipped text in CSS
.clipped_text {
white-space: nowrap;
width: 100%; # for IE 6
overflow: hidden;
text-overflow: ellipsis;
}
@sobstel
sobstel / gist:919114
Created April 14, 2011 08:15
Mac OS X: redirecting port 80 to actual http port
We couldn’t find that file to show.
@sobstel
sobstel / mysql_fast_load.sql
Created May 8, 2011 14:59
MySQL fast data load
#1
LOAD DATA INFILE...
#2
ALTER TABLE name DISABLE KEYS; // tells MySQL to stop updating nonunique indexes
INSERT ...
...
ALTER TABLE name ENABLE KEYS; // re-creates missing indexes (much faster than inserting one by one)
#3 (InnoDB)
@sobstel
sobstel / ternary_operator_gotcha.php
Created May 12, 2011 18:45
PHP new ternary operator gotcha
<?php
// old way
$value = $value ? $value : false;
// new way
$value = $value ?: false;
// however...
$value = isset($value) ?: false; // if eg. $value="value", then it returns (bool)true, and not (string)"value"
@sobstel
sobstel / accessing_private.php
Created May 17, 2011 09:11
Accessing private members of the same object type
<?php
class Test
{
private $foo;
public function __construct($foo)
{
$this->foo = $foo;
}
@sobstel
sobstel / pdo_group_results.php
Created May 31, 2011 19:03
PHP PDO grouping results
<?php
$stmt = $pdo_connection->query('SELECT id, name, surname FROM people');
$people = $stmt->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_UNIQUE | \PDO::FETCH_ASSOC);
/*
$people will now contain:
array(
1 => array(
'name' => 'Juan',
'surname' => 'Sorin',
@sobstel
sobstel / call_class_methods_via_instance.rb
Created November 15, 2011 17:08
Call class method via instance
class SomeClass
def self.some_method
end
end
some_obj = SomeClass.new
some_obj.class.some_method # = SomeClass.some_method
@sobstel
sobstel / beholder.js
Created February 8, 2012 13:17
Observer in JS
/**
* Global beholder for communication between blocks.
*
* If any callback returns true, next callbacks are NOT executed.
*/
var Beholder = function() {
var callbacks = {};
return {
observe: function(id, callback) {