Skip to content

Instantly share code, notes, and snippets.

View al-the-x's full-sized avatar

David Rogers AKA "AL the X" al-the-x

View GitHub Profile
@al-the-x
al-the-x / Planning.markdown
Created August 30, 2011 00:14
Orlando Coding Dojo -- 8/27/2011

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Planning

@al-the-x
al-the-x / main.php
Created October 7, 2011 01:04
OrlandoPHP Coding Dojo - 2011-10-06
<?php
class Solution {
public function cool($val){
if (($val % 3 ) == 0 || ($val % 5) == 0){
return $val;
} return 0;
}
function solveFor ( $limit )
{
@al-the-x
al-the-x / app-config-bootstrap-libraries.php
Created October 26, 2011 14:30
Example of loading the Zend Framework as a Lithium library
<?php
use \lithium\core\Libraries;
// Lots of other stuff...
/**
* Zend Framework 1.11.x is installed via PEAR into the standard PHP include_path
* location. We just need Lithium to know how to get to it.
*/
@al-the-x
al-the-x / main.rb
Created March 10, 2012 15:40
Orlando Ruby Coding Dojo - 3/8/2011
require "enumerator"
class Solution
include Enumerable
def initialize ( cap=nil )
@e = Enumerator.new do |yielder|
a = b = 1
loop do
break if cap && b > cap
@al-the-x
al-the-x / read.php
Created March 30, 2012 14:19
Ingesting a big CSV file, one line at a time...
#!/usr/bin/env php
<?php
/**
* Either make this file executable with `chmod +x read.php` or
* run with `php read.php` passing the input file as the first
* argument, e.g. `php read.php data.csv` or `read.php data.csv`.
* If the file contains a header row, add an environment variable,
* like so: `CSV_HEADER_ROW=1 php read.php data.csv`
*/
@al-the-x
al-the-x / RackspaceCalcs.html
Created June 14, 2012 22:54
Hacking on Rackspace Cloud Pricing
<script src="http://www.rackspace.com/script/loadbalancerscalc.js" type="text/javascript"></script>
<script src="http://www.rackspace.com/script/serverscalc.js" type="text/javascript"></script>
<script src="http://www.rackspace.com/script/serverscalc.js" type="text/javascript"></script>
@al-the-x
al-the-x / README.md
Created July 18, 2012 22:09
Magic Deployments

Magic Deployments are Fun!

  1. Make a --bare --mirror clone in some central location on the server, e.g. /var/git/some-site.git
  2. Clone from that central location into your deployment paths, e.g.
  • git clone /var/git/some-site.git /var/www/some-site.com/
  • Check out the correct branch and setup tracking and all that usual stuff...
  1. Add the contents of config into /var/git/some-site.git/config (don't overwrite)
  2. Use git add-deployed to tell the central repo where your deployments are, e.g.
  • git add-deployed master /var/www/some-site.com/
  1. Setup a cron or a hook that triggers update-mirror and update-deployed for your repo, e.g.
<?php
function next_highest_multiple($number, $multiple)
{
if ( $multiple > $number ) return $multiple;
if ( $multiple == 0 ) return 0;
return ( ($remainder = $number % $multiple) ?
$number + $multiple - $remainder : $number
@al-the-x
al-the-x / env.php
Created October 23, 2012 17:52
Finding OPENSHIFT environment variables in PHP / Zend Server
<?php
$find_openshift_db = function($variables){
$keys = array_filter(array_keys($variables), function($key){
return (strpos($key, 'OPENSHIFT') === 0);
});
return array_intersect_key($variables, array_flip($keys));
};
?>
@al-the-x
al-the-x / borked.haml
Created January 3, 2013 17:24
While using PyHAML to build an app with AngularJS, I noticed that some of my attributes were being "sanitized" when I use a `def` or `block` tag with HAML syntax (e.g. `%%self:some_def` below). The PyHAML preprocessor expands the attribute name on the tag to `ng-app`, then Mako barfs on the `ng-` prefix of the attribute. Woes!
- attrs={ "ngApp": "something" }
%p(**attrs)
This element should have an attribute <code>ng-app="something"</code>. |
It works just fine.
%%(def(name="some_def(**attrs)")
= attrs
%p(**attrs)
= caller.body() or 'Cannot pass a body to a function... :/'