Skip to content

Instantly share code, notes, and snippets.

@ryansukale
ryansukale / ExecuteQuery.php
Last active January 4, 2016 19:59
A simple php snippet for querying data from a database using mysqli
$query="select * from your_table where";
$resultSet = mysqli_query($con,$query);
$size = mysqli_num_rows($resultSet);
if($size>0){
while($resultRow = mysqli_fetch_array($resultSet)){
$fieldValue = $resultRow['field_name'];
}
}
@ryansukale
ryansukale / MysqliInsertUpdate.php
Last active January 4, 2016 20:09
A sample mysqli insert-update statement for strings, numbers and dates.
$now = date("Y-m-d H:i:s");
//Insert
$query = 'insert into '.$tableNamespace.'tableName(field1, field2, field3, field4) values ('.
'"'.$strValue1.'",'.
'"'.$strValue2.'",'.
$intValue3.','.
'"'.$now.'"'.
')';
@ryansukale
ryansukale / timeManipulation.php
Last active January 4, 2016 20:19
Php Script demonstrating how to add/subtract dates
$timeInterval = 10;
$timeFactor = 'seconds'; //Can be either 'days', 'hours', 'minutes' or 'seconds'
$now = date("Y-m-d H:i:s");
$futureDate = date('Y-m-d H:i:s', strtotime($now. ' + '. $timeInterval .' '.$timeFactor));
@ryansukale
ryansukale / node-post.js
Last active August 29, 2015 13:57
A simple template of node post - using multiparty instead of bodyparser
/*
Apparently using bodyParser is bad
http://andrewkelley.me/post/do-not-use-bodyparser-with-express-js.html
This is how you'd fetch post parameters using multiparty instead.
*/
var multiparty = require('multiparty');
//Fetching the value of a field in a post parameter
app.post('/yoururl', function(req, res) {
@ryansukale
ryansukale / phpDebugging.php
Created March 10, 2014 14:40
Two lines of code that can help you debug errors in your php page
ini_set('display_errors', 'On');
error_reporting(E_ALL);
Had to install ubuntu on a usb drive when my hard drive crashed.
Seems like in ubuntu 13.10, the usb-creator-gtk is corrupted. I followed a few instructions at
https://help.ubuntu.com/community/Installation/FromUSBStick and finally managed to install ubuntu on a usb drive.
This is waht had to be done before running startup disk creator
sudo add-apt-repository ppa:jmarsden/lubuntu
sudo apt-get update
sudo apt-get install usb-creator-gtk
@ryansukale
ryansukale / strTrim.js
Created March 27, 2014 18:49
Trimming a string in javascript
//Reference
//http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript
if (!String.prototype.trim) {
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
String.prototype.ltrim=function(){return this.replace(/^\s+/,'');};
String.prototype.rtrim=function(){return this.replace(/\s+$/,'');};
String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');};
//Inspired by https://github.com/klughammer/node-randomstring
function generateRandomCode($length){
$str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz';
$randomChar = $str[rand(0, strlen($str)-1)];
$length= ($length == null)? 32 : $length;
$randomArray = array();
var getData = new Promise(function(resolve, reject){
// Do something asynchronous and pass it a callback
getDataFromAMillionMilesAway(function(data){
if(data){
resolve(data);
}
else {
reject(new Error("Thats too far away"));