Skip to content

Instantly share code, notes, and snippets.

View bruceoutdoors's full-sized avatar
🧗

Lee Zhen Yong bruceoutdoors

🧗
View GitHub Profile
@bruceoutdoors
bruceoutdoors / DbmigrateController.php
Last active June 2, 2019 12:30
Laravel 4 Convert existing MySQL database to migrations. This is a fork of Christopher Pitt's work http://laravelsnippets.com/snippets/convert-an-existing-mysql-database-to-migrations, which is based off michaeljcalkins's work at http://paste.laravel.com/1jdw#sthash.0nEgQzQR.dpuf. His original source code doesn't really work out of the box in my…
<?php
/* * **
*
* This script converts an existing MySQL database to migrations in Laravel 4.
*
* 1. Place this file inside app/controllers/
*
* 2. In this file, edit the index() method to customize this script to your needs.
* - inside $migrate->ignore(), you pass in an array of table
@bruceoutdoors
bruceoutdoors / 2014_02_24_135909_add_permissions.php
Created February 24, 2014 14:32
Laravel 4 Entrust boilerplate migration file for adding predefined permissions - https://github.com/Zizaco/entrust
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddPermissions extends Migration
{
/**
* Run the migrations.
@bruceoutdoors
bruceoutdoors / sine_anim.cpp
Created April 2, 2014 13:00
A tiny console program that plots a sine graph animation. Runs in VC++.
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <windows.h>
using namespace std;
int main()
{
for (int i = 0; i < 100000; i++) {
@bruceoutdoors
bruceoutdoors / matrix_calc.cpp
Created April 16, 2014 09:11
Simple C++ console matrix calculator. All it does is add and substract 3x3 matrices.
// simple matrix calculator
#include <iostream>
#include <cstdlib>
#include <limits>
// A 3x3 matrix
const int M_SIZE = 3;
typedef double matrix[M_SIZE][M_SIZE];
// function prototypes
@bruceoutdoors
bruceoutdoors / makefile
Created July 2, 2014 15:53
Custom GLUI makefile to build in it windows (MinGW).
.SUFFIXES: .cpp
#for sgi -- comment out the lines below to use on HP
#CC=CC -g0 -o32
#CC=gcc
# Compiler options
#OPTS=-g
#OPTS=-O0
#OPTS=-O3
#pragma once
#include <sstream>
#include <iostream>
class Point
{
public:
typedef std::shared_ptr<Point> SPtr;
typedef std::unique_ptr<Point> UPtr;
#include <iostream>
#include <memory>
#include <string>
#include "Point.hpp"
class PointMan
{
public:
PointMan() : q(new Point("q")) {
q->set(6, 12);
#include <iostream>
#include <memory>
#include <string>
#include <cassert>
#include "Point.hpp"
class PointMan
{
public:
static const size_t SIZE = 3;
#include <iostream>
#include <memory>
#include <string>
#include "Point.hpp"
class PointMan
{
public:
static const size_t SIZE = 3;
PointMan() {
@bruceoutdoors
bruceoutdoors / double-precision-fix.cpp
Created November 17, 2014 07:39
when using double, take note of its precision problem (float and double only store decimal estimates) if you find certain values does not match. A possible solution is to use a custom Round function.
#include <iostream>
#include <cmath>
using namespace std;
// rounds a double variable to nPlaces decimal places
double Round(double dbVal, int nPlaces /* = 0 */)
{
const double dbShift = pow(10.0, nPlaces);
return floor(dbVal * dbShift + 0.5) / dbShift;