Skip to content

Instantly share code, notes, and snippets.

@etrepat
etrepat / baum-standalone.php
Created March 4, 2015 19:24
Using Baum with stand-alone Eloquent (Capsule) - Laravel 5.0.x
<?php
require __DIR__ . '/vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as DB;
use Baum\Node;
// Initialize Capsule
$capsule = new DB;
// Add connection settings
@etrepat
etrepat / baum-standalone.php
Last active November 21, 2016 15:31
Using Baum with stand-alone Eloquent (Capsule) - Laravel 4.2.x
<?php
require __DIR__ . '/vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as DB;
use Baum\Node;
// Initialize Capsule
$capsule = new DB;
// Add connection settings
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
@etrepat
etrepat / traversing-example.md
Last active April 8, 2021 15:57
Traversing the Hierarchy Tree with Baum - An Example

The simplest way to traverse the hierarchy tree with Baum is by iterating through the children relation.

<?php

$root = Category::roots()->with('children')->first();

echo "<h3>{$root->name}</h3>";

foreach($root->children as $category) {
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
*/
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = 'video.mp4';
@etrepat
etrepat / bundler-exec.sh
Created December 12, 2011 11:03
Automatically run Ruby scripts with "bundle exec". Source: gma/bundler-exec
#!/bin/bash
BUNDLED_COMMANDS="${BUNDLED_COMMANDS:-
cap
capify
cucumber
foreman
guard
haml
heroku
@etrepat
etrepat / dnsd.rb
Created December 7, 2011 22:12 — forked from peterc/dnsd.rb
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL
@etrepat
etrepat / FIle.sublime-settings.json
Created October 15, 2011 18:44
Sublime Text 2 - My Settings
{
// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
// Note that the font_face and font_size are overriden in the platform
// specific settings file, for example, "Base File (Linux).sublime-settings".
// Because of this, setting them here will have no effect: you must set them
// in your User File Preferences.
"font_face": "Monaco",
"font_size": 12,
@etrepat
etrepat / class_instance_vars.rb
Created July 26, 2011 10:56
Why I don't use class variables in Ruby (or try not to)
class Person
@name = nil
# class-level reader
# cattr_accessor is rails-specific not ruby, and uses class vbles so ...
# may be done like this too:
#
# class << self
# attr_reader :name
# end
@etrepat
etrepat / triangle_check.rb
Created July 14, 2011 10:55
Check if a given point is inside a triangle
# encoding: utf-8
require 'pp'
class Point
attr_accessor :x, :y
def initialize(x=0.0, y=0.0)
@x = x
@y = y
end