Skip to content

Instantly share code, notes, and snippets.

@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'));
@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 / 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 / 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 / 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 / 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 / app.js
Last active August 29, 2015 14:24
ReactJS Modal
'use strict';
import { createClass } from 'react/addons';
let App = createClass({
render: function() {
return <div>
<Button label="Open!" target="modalTest" classNames=".buttonStyle" />
<Modal name="modalTest">
<div class='modal'>
@kinncj
kinncj / oauth.js
Created July 17, 2015 22:22
Pebble OAuth Handler
function hex_sha1(e){return binb2hex(core_sha1(str2binb(e),e.length*chrsz))}function b64_sha1(e){return binb2b64(core_sha1(str2binb(e),e.length*chrsz))}function str_sha1(e){return binb2str(core_sha1(str2binb(e),e.length*chrsz))}function hex_hmac_sha1(e,t){return binb2hex(core_hmac_sha1(e,t))}function b64_hmac_sha1(e,t){return binb2b64(core_hmac_sha1(e,t))}function str_hmac_sha1(e,t){return binb2str(core_hmac_sha1(e,t))}function sha1_vm_test(){return"a9993e364706816aba3e25717850c26c9cd0d89d"==hex_sha1("abc")}function core_sha1(e,t){e[t>>5]|=128<<24-t%32,e[(t+64>>9<<4)+15]=t;for(var r=Array(80),n=1732584193,a=-271733879,o=-1732584194,u=271733878,h=-1009589776,c=0;c<e.length;c+=16){for(var s=n,i=a,f=o,l=u,d=h,A=0;80>A;A++){16>A?r[A]=e[c+A]:r[A]=rol(r[A-3]^r[A-8]^r[A-14]^r[A-16],1);var m=safe_add(safe_add(rol(n,5),sha1_ft(A,a,o,u)),safe_add(safe_add(h,r[A]),sha1_kt(A)));h=u,u=o,o=rol(a,30),a=n,n=m}n=safe_add(n,s),a=safe_add(a,i),o=safe_add(o,f),u=safe_add(u,l),h=safe_add(h,d)}return Array(n,a,o,u,h)}function sha1
@kinncj
kinncj / index.php
Created August 13, 2015 14:18
ZCEs from CANADA
<?php
function readStdin($message = null)
{
if ($message) {
echo $message.PHP_EOL;
}
$fr=fopen("php://stdin","r");
$input = fgets($fr,128);
$input = rtrim($input);
@kinncj
kinncj / Enum.php
Created September 17, 2015 20:07
Enum
<?php
abstract class Enum extends \ArrayObject
{
public final function __construct()
{
$constantsToRemove = ['STD_PROP_LIST', 'ARRAY_AS_PROPS'];
$constants = (new \ReflectionObject($this))->getConstants();
foreach ($constants as $constant => $value) {