Skip to content

Instantly share code, notes, and snippets.

@gonzalo123
gonzalo123 / gist:10007768
Created April 6, 2014 15:41
Kata Katayuno Abril Bilbao sin TDD
<?php
echo (new \DateTime())->diff(\DateTime::createFromFormat('Y-m-d H:i:s', json_decode((new Guzzle\Http\Client('http://karmacracy.com'))->get('/api/v1/user/gonzalo123')->send()->getBody(), true)['data']['user'][0]['date_signed']))->format('%y') . "year/s old";
@gonzalo123
gonzalo123 / js.php
Created February 24, 2011 17:07
Combines recursively js files into a single one to speed up page loads
//js.php
require 'jsmin.php';
function checkCanGzip(){
if (array_key_exists('HTTP_ACCEPT_ENCODING', $_SERVER)) {
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) return "gzip";
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false) return "x-gzip";
}
return false;
}
@gonzalo123
gonzalo123 / Dummy.cs
Created October 13, 2011 18:51
Example static and non static functions
class Dummy
@helloStatic: (name)->
"hello #{name} (static)"
hello: (name) ->
"hello #{name}"
alert Dummy.helloStatic("Gonzalo")
dummy = new Dummy
@gonzalo123
gonzalo123 / DocInject.php
Created April 9, 2012 13:23
DocInject class
<?php
class DocInject
{
public function __construct()
{
$reflection = new ReflectionClass($this);
foreach ($reflection->getProperties() as $property) {
$this->processProperty($property);
}
}
@gonzalo123
gonzalo123 / DocInject.trait.php
Created April 9, 2012 13:25
DocInject trait
<?php
trait DocInject
{
public function parseDocInject()
{
$reflection = new ReflectionClass($this);
foreach ($reflection->getProperties() as $property) {
$this->processProperty($property);
}
}
@gonzalo123
gonzalo123 / gist:868939
Created March 14, 2011 09:31
push existing repository to github
cd existing_git_repo
git remote add origin git@github.com:[user]/[reponame].git
git push -u origin master
#!/usr/bin/env bash
PATH=/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
# actual battery level
BATT=`ioreg -c AppleDeviceManagementHIDEventService -r -l | grep -i mouse -A 20 | grep BatteryPercent | cut -d= -f2 | cut -d' ' -f2`
# defaults to warn at 20%; accepts other number as 1st argument (useful for testing)
COMPARE=${1:-20}
if [ -z "$BATT" ]; then
@gonzalo123
gonzalo123 / logger.py
Created October 27, 2020 09:24
python logger
import logging
logging.basicConfig(
format='%(asctime)s [%(levelname)s] %(message)s',
level='INFO',
datefmt='%d/%m/%Y %X')
logger = logging.getLogger(__name__)
@gonzalo123
gonzalo123 / auth.py
Created October 27, 2020 09:27
flask Autorization Bearer
from functools import wraps
from flask import request, abort
from lib.logger import logger
def authorize_bearer(bearer):
def authorize(f):
@wraps(f)
def decorated_function(*args, **kws):
if 'Authorization' not in request.headers: