Skip to content

Instantly share code, notes, and snippets.

View aaryadev's full-sized avatar
💭
I may be slow to respond.

Aaryadev aaryadev

💭
I may be slow to respond.
View GitHub Profile
function getId(url) {
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
return match[2];
} else {
return 'error';
}
}
@aaryadev
aaryadev / eeprom.lua
Created February 16, 2019 07:54
nodemcu read EEPROM lua
print("eeprom")
GPIO_PIN = 7 --interrupt pin
id=0
device = 0x50 -- address of EEPROM
memadr=0x00 -- let's read from begining
sda, scl = 4,5
i2c.setup(id, sda, scl, i2c.SLOW)
buffer = adc.read(0)
--string.sub (buffer, 1 , 40)
--string.sub (buffer, 4 , 11)
@aaryadev
aaryadev / Api.php
Created August 29, 2018 08:23
Code igniter API Header setting for JSON output
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Api extends CI_Controller {
function __construct(){
parent:: __construct();
$this->output->set_header("Access-Control-Allow-Origin: * ");
$this->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
$this->output->set_header("HTTP/1.0 200 OK");
@aaryadev
aaryadev / .htaccess
Created April 4, 2017 06:36
Codeigniter htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
@aaryadev
aaryadev / thumbnail_generator.php
Created May 27, 2016 23:24
PHP thumbnail creator
<?php
function makeThumbnails($updir, $img, $id)
{
$thumbnail_width = 134;
$thumbnail_height = 189;
$thumb_beforeword = "thumb";
$arr_image_details = getimagesize("$updir" . $id . '_' . "$img"); // pass id to thumb name
$original_width = $arr_image_details[0];
$original_height = $arr_image_details[1];
if ($original_width > $original_height) {
@aaryadev
aaryadev / convert.php
Created May 12, 2016 06:07
reduce image size using php and shell command, convert and php is very common in ubuntu using them compress/resize the images in folder.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
$count=0;
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
$output= shell_exec('convert -resize 50% '.$fileinfo->getFilename().' '.$count.'.jpg');
}
$count++;
}
@aaryadev
aaryadev / QRLogo.php
Created March 23, 2016 21:16 — forked from NTICompass/QRLogo.php
QR Code + Logo Generator
<?php
/**
* QR Code + Logo Generator
*
* http://labs.nticompassinc.com
*/
$data = isset($_GET['data']) ? $_GET['data'] : 'http://labs.nticompassinc.com';
$size = isset($_GET['size']) ? $_GET['size'] : '200x200';
$logo = isset($_GET['logo']) ? $_GET['logo'] : FALSE;
@aaryadev
aaryadev / curl_file_post.php
Created April 6, 2015 16:29
Post file to server via php (cUrl)
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@/path/to/file.txt'));
curl_setopt($ch, CURLOPT_URL, 'http://server2/upload.php');
curl_exec($ch);
@aaryadev
aaryadev / MoonPhase.php
Created April 3, 2015 16:10
MoonPhase
<?php
class MoonPhase {
private $timestamp;
private $phase;
private $illum;
private $age;
private $dist;
private $angdia;
private $sundist;
private $sunangdia;
@aaryadev
aaryadev / gpsdistance
Created February 28, 2015 06:57
distance between 2 gps location
static double EARTH_RADIUS = 6378100;// radius of earth in meters
public static double gpsdistance (double lat1, double long1, double lat2, double long2)
{
//in meters :D
double degToRad= Math.PI / 180.0;
double phi1 = lat1 * degToRad;
double phi2 = lat2 * degToRad;
double lam1 = long1 * degToRad;
double lam2 = long2 * degToRad;