Skip to content

Instantly share code, notes, and snippets.

View JoshuaEstes's full-sized avatar
👨‍💻

Joshua Estes JoshuaEstes

👨‍💻
View GitHub Profile
@JoshuaEstes
JoshuaEstes / Vagrantfile
Last active December 15, 2015 08:29
Vagrantfile for symfony2
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/var/www/app.local", :nfs => true
config.vm.provider :virtualbox do |vb|
@JoshuaEstes
JoshuaEstes / satoshi-picks.php
Last active December 11, 2015 00:19
get 20 numbers from a bitcoin transaction hash
<?php
// get the sha512 hash of the txid and split it by 2
$pool = str_split(hash_hmac('sha512', $txid, $DailySecretKey), 2);
// Loop and get 20
for($N=array(),$i = 0; count($N) < 20 && $i < count($pool); $i++) {
// base 10 that shit
$n = hexdec($pool[$i]);
// make sure it meets the standards
if ($n > 80 || $n < 1) {
@JoshuaEstes
JoshuaEstes / random.php
Created January 10, 2013 17:51
Select n random elements from N without replacement.
<?php
/**
* This function will take an array and select n from it
* without replacement. This can be used as a random number
* generator
*
* Example: I want to select $n numbers from a pool of $N numbers
* <code>
* $values = $srs(range(1,100), 5);
* </code>
@JoshuaEstes
JoshuaEstes / math.php
Last active December 10, 2015 19:19
PHP Math functions =D
<?php
/**
* Computes the factorial of $n
* @param interger $n Number you want to find the factorial for
* @return string
*/
$factorial = function($n) {
for($k=1, $i=1;$i <= $n;$i++) {
$k = $k * $i;
@JoshuaEstes
JoshuaEstes / controller.php
Created October 5, 2012 15:13
Symfony2 Redirect with hashtag
<?php
namespace Acme\BlogBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class AttachmentController extends Controller
{
public function redirectAction()
@JoshuaEstes
JoshuaEstes / user.sh
Last active October 10, 2015 07:57
Script to create a deployment user on a linux box
# Remote Server
useradd www-deploy -c "Deployment User" -d /home/www-deploy -G www-data -m -s /bin/bash
sudo su - www-deploy
# Localhost
ssh-keygen -t rsa
# Append your key to the Remote host authorized keys file
cat id_rsa.pub >> ~/.ssh/authorized_keys
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
/**
* This assumes you already have a User entity, this just shows the parts
* required
<?php
namespace AppBundle\Form\DataMapper;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Security\Core\User\UserInterface;
class UserSettingDataMapper implements DataMapperInterface
{
public function mapDataToForms($data, $forms)