Skip to content

Instantly share code, notes, and snippets.

@kinncj
kinncj / Map.php
Last active September 21, 2015 15:51
Map
<?php
class Map extends ArrayObject
{
public function __construct($input = [], $flags = 0, $iterator_class = "ArrayIterator")
{
parent::__construct([], $flags, $iterator_class);
foreach ($input as $k=>$v) {
$this[$k] = $v;
@kinncj
kinncj / Dilmas.php
Last active June 6, 2017 13:54
Dilmas Currency
<?php
class Dilmas extends \SplFloat
{
public function __construct($value)
{
$currency = json_decode(file_get_contents('http://api.fixer.io/latest?base=USD&symbols=BRL'), true);
$brl =(float) $currency['rates']['BRL'];
parent::__construct(((float) round($value / $brl, 2)));
@kinncj
kinncj / String.prototype.js
Last active August 12, 2016 14:44
String.replaceMap(parameterList);
String.prototype.replaceMap = function(parameters) {
var string = this.toString();
Object.keys(parameters).forEach(function(key){
string = string.replace(new RegExp(key, 'g'), parameters[key]);
});
return string;
}
@kinncj
kinncj / message.js
Created August 22, 2016 23:03
console log message
(function() {
var m = 'font-family:monospace;color:#';
if(window.console) {
console.log('%cyour %cmessage %chere! %chttp://www.site.com', m+'1EFF00',m+'FF0000',m+'668CFF', m+'C6F612');
}
}())
@kinncj
kinncj / sorting.php
Created August 30, 2016 00:24
Sorting in PHP
<?php
function bubble(array $array)
{
$n = count($array);
for($counter = 1; $counter < $n; $counter++) {
for ($current = $n -1; $current >= $counter; $current--) {
$next = $current - 1;
@kinncj
kinncj / binaryTree.php
Created August 30, 2016 00:35
binaryTree max height PHP
<?php
class Node
{
private $left;
private $right;
public function __construct(Node $left = null, Node $right = null)
{
$this->left = $left;
@kinncj
kinncj / SuaPlatform.php
Created December 20, 2016 18:24
questão do joubertredrat no PHPSP - Slack
<?php
SuaPlatform extends MySQLWHateverPlatform
{
/** .. **/
public function getDefaultValueDeclarationSQL($field)
{
$default = parent::getDefaultValueDeclarationSQL($field);
$this->decorateDatetime($field, $default);
@kinncj
kinncj / FileObject.php
Created January 10, 2017 17:05
SplFileObject::getMimeType()
<?php
class FileObject extends \SplFileObject
{
private $size;
public function fwrite($content, $len = null) // :int
{
$this->size = $len ?: strlen($content);
@kinncj
kinncj / README.md
Last active January 30, 2017 16:51
Common interview questions

Those are the 3 most common interview questions...

  • Sorting:
    • Bubble, or sinking sort
      • Seeks for the lowers value, swaps in the inner level
        • Means that every iteration would swap values
    • Selection:
      • Seeks for the lowest value, swaps only when found AT the outter level
        • Means that not all iteration would swap values
@kinncj
kinncj / .bash_profile
Last active August 10, 2017 14:18
few things
# ~/.bash_profile
# ...
# Docker cleanup
dcleanup(){
docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null
docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null
}
# Git cleanup
gitcleanup() {