Skip to content

Instantly share code, notes, and snippets.

var humanFileSize = function(size) {
var i = Math.floor( Math.log(size) / Math.log(1024) );
return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}
<?php
// Return array with proper private and protected property names
function dismount($object) {
$reflectionClass = new ReflectionClass(get_class($object));
$array = array();
foreach ($reflectionClass->getProperties() as $property) {
$property->setAccessible(true);
$array[$property->getName()] = $property->getValue($object);
$property->setAccessible(false);
@mikemadisonweb
mikemadisonweb / transaction.php
Created July 28, 2016 11:49 — forked from datacow-com/transaction.php
How to make transactions in Doctrine 2 using Symfony 2
<?php
// Snippet for Symfony 2 application that uses Doctrine 2 to handle transactions
// It uses the names of the objects/doctrine repositories from the Beta 4 Manual of Symfony 2.
// Get the entity manager
$em = $this->getDoctrine()->getEntityManager();
// suspend auto-commit
$em->getConnection()->beginTransaction();
var yourApp = (function (/* outer scope variables*/) {
function User () {
/* stuff */
}
User.prototype.someMethod (arg) {
state.users[this.id].something = arg;
}
function App () {
@mikemadisonweb
mikemadisonweb / baseConverter.js
Created August 15, 2016 11:55 — forked from faisalman/baseConverter.js
Convert From/To Binary/Decimal/Hexadecimal in JavaScript
/**
* Convert From/To Binary/Decimal/Hexadecimal in JavaScript
* https://gist.github.com/faisalman
*
* Copyright 2012-2015, Faisalman <[email protected]>
* Licensed under The MIT License
* http://www.opensource.org/licenses/mit-license
*/
(function(){
<?php
/**The following class generates VALID RFC 4211 COMPLIANT Universally Unique IDentifiers (UUID) version 3, 4 and 5.
* Version 3 and 5 UUIDs are named based. They require a namespace (another valid UUID) and a value (the name). Given the same namespace and name, the output is always the same.
* Version 4 UUIDs are pseudo-random.
* UUIDs generated below validates using OSSP UUID Tool, and output for named-based UUIDs are exactly the same. This is a pure PHP implementation.
*/
class UUID {
public static function v3($namespace, $name) {
if(!self::is_valid($namespace)) return false;
UPDATE TABLE_NAME
SET url_string=REPLACE(url_string, 'http://www.base_url.com/', '')
WHERE 1
@mikemadisonweb
mikemadisonweb / Paypal.php
Created August 23, 2016 07:26 — forked from danvbe/Paypal.php
Sonata PayPal issue fix
<?php
/**
* Created by PhpStorm.
* User: danvbe
* Date: 7/25/14
* Time: 2:49 PM
*/
namespace Application\Sonata\PaymentBundle\Component;
@mikemadisonweb
mikemadisonweb / 1-Explanations.md
Created August 23, 2016 07:27 — forked from danvbe/1-Explanations.md
A way to integrate FosUserBundle and HWIOAuthBundle

I have managed to install this… and make it work. I implemented it for Facebook and Google, but you can extend it. My solution it is mostly as described in #116, with a bit of more code presented. The key aspects that lack in the #116 presentation (IMO) are:

  • the registration as service of your custom FOSUBUserProvider (with the necessary parameters)
  • set the service for oauth_user_provider in the security.yml with your custom created service

Here are the steps:

  1. Routing. In routing.yml I have added all the routes for both bundles.
  2. Configuration. I have set the config.yml mostly as it is presented in the HWIOAuthBundle.
  3. Security. I have set the security.yml mostly as it is presented in the HWIOAuthBundle (though my routes are using /login pattern, not /connect). Also, the oauth_user_provider is set for my custom service.
@mikemadisonweb
mikemadisonweb / LinkedList.class.php
Created August 24, 2016 13:23 — forked from zachflower/LinkedList.class.php
PHP implementation of a singly linked list.
<?php
class Node {
public $data = NULL;
public $next = NULL;
public function __construct($data = NULL) {
$this->data = $data;
}
}