Skip to content

Instantly share code, notes, and snippets.

View AnowarCST's full-sized avatar

Anowar Hossain AnowarCST

View GitHub Profile
@AnowarCST
AnowarCST / exportCSV.php
Last active August 29, 2015 14:26
Data export as CSV
<?php
function exportCSV($id, $data) {
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=report_$id.csv");
if ($data && count($data[0]) > 0) {
$rc = 0;
foreach ($data[0] as $key => $value) {
if ($rc > 0) {
echo ',';
} $rc++;
@AnowarCST
AnowarCST / Captcha.php
Last active August 29, 2015 14:20
CI Class for create Captcha Image
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Captcha extends CI_Controller {
public function __construct() {
parent::__construct();
}
//Settings: You can customize the captcha here
public function index($rand = 100) {
@AnowarCST
AnowarCST / valid_email.patch
Created April 5, 2015 11:49
CI_Email::valid_email() hostname validation
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index c70144f..8968a84 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -704,11 +704,37 @@ class CI_Email {
* Email Validation
*
* @param string
+ * @param mixed types of records to check
* @return bool
@AnowarCST
AnowarCST / TestAPI.php
Created April 5, 2015 10:19
Making a test API
<?php
require_once './API.class.php';
class MyAPI extends API
{
protected $User;
public function __construct($request, $origin) {
parent::__construct($request);
// Abstracted out for example
@AnowarCST
AnowarCST / curl_call.php
Last active August 29, 2015 14:18
Using Curl in PHP
<?php
// header('Content-Type: application/xml; charset=utf-8');
// header('Content-Type: application/json');
// Page Name : index.php
$params = array(
"apiKey" => "30aNowar50Hossain42",
"User" => "anowar",
"token" => "1001",
"student" => "anowar",
"roll" => "305042",
@AnowarCST
AnowarCST / ExportReport.php
Last active August 29, 2015 14:18
Export Report as Excel & Doc
public function exportReport($report_id,$type){
$reportData = $this->getReportById($report_id);
$filename=preg_replace("/[^a-zA-Z]+/", "", $reportData['REPORT_TITLE']);
include_once "report_helper.php";
if($type =='word'){
header('Content-Type: application/msword');
header("Content-Disposition: attachment; filename=$filename.doc");
}else{
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=$filename.xls");
@AnowarCST
AnowarCST / DbClass.php
Last active August 29, 2015 14:18
Oracle DB Connection with Query
<?php
class Db {
public $url = 'http://localhost/DashboardObject/';
protected $host = '192.--.--.54';
protected $SID = 'qpro';
protected $userName = 'brac_central_db';
protected $password = '123456';
protected $port = '1521';
protected $db;
public function __construct(){
@AnowarCST
AnowarCST / Encryption.php
Last active August 29, 2015 14:18
Encryption library Class
<?php
class Encryption{
var $defskey = "NibidAlo"; // Encryption Key
public function safe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return urlencode($data);
}
@AnowarCST
AnowarCST / magic_square.cpp
Last active August 29, 2015 14:17
Magic square
// Magic square Algorithm
/*
* Logic:
1. set 1 in first row centre
2. then upper->left = key [key=2,3,4....]
3. if not empty (upper->left) then find the buttom of last node = key
*/
#include <iostream>
#include <string>
using namespace std;
@AnowarCST
AnowarCST / convert_sqlpara.php
Last active August 29, 2015 14:16
Convert SQL Parameter (SQL inside Variable)
<?php
function ConvertSqlPara($sql, $data) {
$start = strpos($sql, '{$');
$i=0;
while ($start>-1) {
$end = strpos($sql, '}', $start);
if($i++>20) {return $sql ;}
if ($end > $start) {
$filed = substr($sql, $start + 2, $end - $start - 2);
$var=array('','');