Skip to content

Instantly share code, notes, and snippets.

@kinncj
kinncj / wtf.rb
Created January 16, 2015 15:56
wtf? construct return different type
class ConcreteKlass
def self.new()
return []
end
end
obj = ConcreteKlass.new
print obj.inspect #WHY? WHYYY? Hey, let's instantiate new ConcreteKlass, now, it's an array? WTF!
@kinncj
kinncj / pick.php
Created January 31, 2014 20:41
pick.php
<?php
echo "\n--------------------------------------------------------------------------------------------------\n";
echo "| Git cherry-pick tool |";
echo "\n--------------------------------------------------------------------------------------------------\n";
if (empty($argv[1]) || empty($argv[2])) {
die("Usage: php pick.php [/git/repo/path] [hash]\n");
}
@kinncj
kinncj / Chat.php
Last active December 29, 2015 15:59
Socketo.me implementation
<?php
//src/WsChatter/Chat.php
namespace WsChatter;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface {
protected $clients;
public function __construct() {
@kinncj
kinncj / cliente.php
Created November 24, 2013 11:19
https://www.facebook.com/groups/nao.tem.biscoito/ "Tiago Oliveira Farias: PHP Object to Json Without Namespace: Tenho um classe "Cliente" dentro de um namespace: "Model", ao converter para "array" (pois preciso enviar retornar via json) os índice do array são formados pelo nome da namespace junto com nome da classe e o nome da propriedade, algo …
<?php
namespace Model;
use PHPFluent\JSONSerializer\Serializer;
class Cliente extends Serializer
{
/**
* @PHPFluent\JSONSerializer\Attribute
*/
@kinncj
kinncj / gitLinter.sh
Created November 22, 2013 21:02
run JSLint for all changed js files
#!/bin/bash
JSLINT="jslint --indent 4 --white true"
for file in $(git status | grep -P '\.((js)|(html)|(json))$'); do
if node $JSLINT $file 2>&1 | grep 'No errors found' ; then
echo "jslint passed ${file}"
exit 0
else
node $JSLINT $file
@kinncj
kinncj / Db.php
Created May 10, 2013 00:08
PDO and it's magics - PHP Brasil - May 9, 2013
<?php
class Db
{
private $pdo;
protected $table;
public function __construct()
{
$parameters = json_decode(file_get_contents('config.json'));