Skip to content

Instantly share code, notes, and snippets.

View mogetutu's full-sized avatar

Isaak Mogetutu mogetutu

View GitHub Profile
@mogetutu
mogetutu / database.php
Last active August 29, 2015 14:02
database_Question
<?php
/**
* Database Query Result Set
* @param string $query SQL Statement eg "SELECT * FROM students"
* @return array array from database result
*/
public function db_query($query)
{
// Run the $query using $this->connection() which
// is the database connection in the previous function
@mogetutu
mogetutu / fix_mysql_osx.sh
Created June 17, 2014 18:53
Fix mysql permission on OS X
sudo chown -R mysql /usr/local/mysql/data/
@mogetutu
mogetutu / gwijie.sh
Created June 9, 2014 11:26
Meteor Quick Script
$ curl https://install.meteor.com | /bin/sh
$ meteor create ~/my_cool_app
$ cd ~/my_cool_app
$ subl .
@mogetutu
mogetutu / replace.sql
Last active August 29, 2015 14:01
replace string-part in mysql
UPDATE table SET fieldname=REPLACE(fieldname, 'MB', '')
class ArrayToXML
{
/**
* The main function for converting to an XML document.
* Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
*
* @param array $data
* @param string $rootNodeName - what you want the root node to be - defaultsto data.
* @param SimpleXMLElement $xml - should only be used recursively
* @return string XML
@mogetutu
mogetutu / csv.export.1.php
Created May 20, 2014 19:56
Larave CSV export
public function get_export()
{
$table = Cpmreport::all();
$file = fopen('file.csv', 'w');
foreach ($table as $row) {
fputcsv($file, $row->to_array());
}
fclose($file);
return Redirect::to('consolidated');
}
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
<?php
# Separated with comma. Empty string - all ips allowed.
# Look in admin panel for GitHub public IP's
# Example: '127.0.0.1, 192.168.1.1'
define('__ALLOWED_IPS__', '94.45.140.46, 207.97.227.253, 50.57.128.197');
# Emails to send sync results
define('MAIL_TO', '[email protected]');
# Mail everything, including logs.
#!/usr/bin/env ruby
# Please read http://otobrglez.opalab.com for more information about this code.
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
require 'benchmark'
class SlowTrie
attr_accessor :word, :nodes
def initialize
@word, @nodes = false, {}
end
def <<(word)