Showing posts with label 7. Show all posts
Showing posts with label 7. Show all posts

Wednesday, July 16, 2014

[MySQL] Grouping Intervals and counting columns

Say you have table like this...

idcodedateactivity
12002014/06/04
22002014/05/04
35002014/04/04
45042014/05/28

...and now you want to get the past 7 days but count how many times 200 (success code) comes up and how many times a number other than 200 (failure code) comes up. So the idea is simple. Get total of success + failure codes, left outer join for success, left outer join for failure. The filter where the date is more the the current day minus 7 days. At the end, you should return a row that has the day, total count, success count, and failure count. the Got it? Yes you do. You're a trooper. Here is a sample:

select STR_TO_DATE(a.period, '%m-%d-%y') as period, ifnull(a.cnt,0) total, ifnull(b.cnt,0) success, ifnull(c.cnt,0) failure 
from
(
select
date_format(dateactivity , '%m-%d-%y') period,
count(*) cnt
from mytable
where dateactivity >= DATE_ADD(NOW(), INTERVAL -7 DAY)
group by date_format(dateactivity , '%m-%d-%y')
) a 
left outer join
(
select
date_format(dateactivity , '%m-%d-%y') period,
count(*) cnt
from mytable
where code = '200'
and dateactivity >= DATE_ADD(NOW(), INTERVAL -7 DAY)
group by date_format(dateactivity , '%m-%d-%y')
) b on a.period = b.period 
left outer join
(
select
date_format(dateactivity , '%m-%d-%y') period,
count(*) cnt
from mytable
where (code != '200' or code is null)
and dateactivity >= DATE_ADD(NOW(), INTERVAL -7 DAY)
group by date_format(dateactivity , '%m-%d-%y')
) c on a.period = c.period
;

I know that there are probably different ways of doing this. If you know how, please share. Sharing is caring. And I care for all.

Wednesday, April 17, 2013

[MySQL] Installing MySql on windows 7 no-installer


Getting the MySQL service to work
  • Extract the file contents to desired directory.
  • Create a 'my.ini' file in the root of the new directory.
  • Copy the following info into my.ini:
[mysqld]
 basedir = C:/mysql
datadir = C:/mysql/data
port = 3306
socket = /tmp/mysql.sock


  • In command line, run ' mysqld --install ' to add the MySQL service
  • Run MySQL service 
  • Then just run mysql to start mysqling. lol
Creating Users

  • Run mysql
  • Type in: create user 'username'@'localhost' identified by 'password'
  • Grant privileges by using the following as guidelines:
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost' -> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%' -> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
GRANT USAGE ON *.* TO 'dummy'@'localhost';

Tuesday, April 16, 2013

[PHP] Installing PHP, Apache, Laravel locally on Windows 7

This guide is only for note taking purposes. Whenever I set up something for the first time, I feel like writing about it. I don't know why that is, but don't worry about it and let's begin.

Installing PHP 5.4 and Apache 2.4:
  • Download Apache 2.4 from apachelounge.com
  • Download PHP 5.4 from the php.net
  • Extract Php files into a directory. You can choose c:\php if you want.
  • I think Apache 2.4 comes in a zip. So just extract the contents into a directory of choice. I use c:\apache
Configuring PHP and Apache

  • In command line, install Apache as a service by running this in cmd: httpd -k install
  • Navigate to Apache's configuration directory and open httpd.conf in a text editor
  • Add the following lines

# PHP Stuff #####################################
#
LoadModule php5_module "c:/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php


# configure the path to php.ini
PHPIniDir "C:/php"


  • Change the listening port if necessary. You may want IIS to be on 80 and Apache on 8080. Or vice versa
  • Start apache!!!
Install Laravel
  • Download Laravel 4. Search on google. And follow the tutorial on the Tut+ site
  • If you're migrating and seeding the database, you need to add $this->call('TableNameTableSeeder') make the following class:


class TableNameTableSeeder extends Seeder {

    public function run()
    {
        DB::table('tablename')->delete();
        User::create(array(
                'id' => 1,
                'username' => 'firstuser',
                'password' => Hash::make('first_password'),
                'created_at' => new DateTime,
                'updated_at' => new DateTime
        ));   
    }
}


Sunday, February 10, 2013

Asus G75VW Boot Recovery. Formatting is not an option!!!!!

Hey guys,
I just got a new Asus G75VW with Windows 7 Ultimate loaded (in place of Home Premium). I do not have an Ultimate disk nor the Home Premium (except for the CD key in the bottom of the laptop). The current Windows was booting by EFI so this was going to be a special solution.

I completely f'd up my Asus G75VW laptop by messing with EasyBCD. In detail, I messed up by using EasyBCD 1.6, since adding a new entry has the ability to choose Generic x86 as the boot type or whatever. I needed this option because lots of hackintosh tutorials used this. Turns out, EasyBCD 1.6 is not supported by Win7. I loaded some defaults with EasyBCD, saved it, and restarted my computer. NOW YOU CAN POUND ME INTO A PANCAKE!!!!!

So when I boot, windows boot manager loads into an error screen that says something is wrong with the BCD. The location was either of the error was either (forgot which displayed first):

/EFI/Microsoft/Boot/BCD

or

/Boot/BCD


So, what are my options? A. Fix the boot for Windows Ultimate. B. Format the drive with Windows Home Premium. I opted for A: So what worked and what didn't?

- When doing a search, I found a lot of people suggest using the Repair disk in the Windows Install DVD. This DID NOT WORK....yet. Something about being EFI bootable will show an incompatibility error no matter which Windows disk I used.

Then I downloaded the Hiren Boot CD 15.2!!!!

- Then I used DiskGenius, which was part of the CD. This may work for some, but it totally f'd up my BCD. Refer to here:

http://www.sevenforums.com/installation-setup/228504-missing-boot-manager-4.html

Using it pretty much just made the whole drive unallocated, although the partitions were still there, but lost.

- Then I used Partition Recovery Wizard, another utility in the CD. I basically used this to find partitions and repair it. It successfully did.

- Now when I restarted the computer, it would say BootMgt is missing.

- So I popped in a Windows 7 disk. At the installation screen, I pressed shift+f10 to go to the command line and I ran all the bootrec commands. It successfully did.This also assigned a drive to the BCD. So you when you run bcdedit in command line, you see "partition=c:" instead of {unknown}

- I believe it still didn't boot then. So now I booted up the Windows 7 Ultimate DVD and hit the repair disk option. Finally!!! It passed the incompatibility error. Now all I did was choose the option to fire up the Startup Recovery.

- When I booted, now there are 2 options for this drive. To boot off the Windows Boot Manager or the drive itself. The boot manager, I believe, boots off the EFI partition. This will obviously create an error since I did not fix this. So if I boot off the hard drive itself, it will FINALLY LOAD INTO WINDOWS! YA!

Conclusion:

I know this was not a clean fix, since I converted from EFI to MBR boot (or is it GPT or MBR boot?). Anyways, I am not a claimed IT, hardware expert either. But I'm just glad this thing is finally working.