Skip to content

Instantly share code, notes, and snippets.

View Ajax30's full-sized avatar
🏠
Working from home

Razvan Zamfir Ajax30

🏠
Working from home
View GitHub Profile
@Ajax30
Ajax30 / itemsloader.js
Last active September 5, 2016 19:40
Infinite scroll to load PHP files
function loadNewItems(){
var win = $(window);
var scrollCount = 0;
// Bind window scroll event
win.scroll(function() {
// If End of document reached
if ($(document).height() - win.height() == win.scrollTop()) {
// path to the file containing the code to load
@Ajax30
Ajax30 / chromeLoginDataExporter.js
Last active July 9, 2017 16:09
Export the passwords stored in your Google Chrome browser
var decryptedRow="";
var pm = PasswordManager.getInstance();
var model = pm.savedPasswordsList_.dataModel;
var pl = pm.savedPasswordsList_;
for(i=0;i<model.length;i++){
PasswordManager.requestShowPassword(i);
};
setTimeout(function(){
var bootstrapStylesheet = '<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">';
tableStart = '<table class="table table-striped"><thead>';
@Ajax30
Ajax30 / addargs.js
Created November 12, 2016 07:26
Add ALL the arguments passed to a function
function add(){
var sum = 0;
// Use "the arguments object" to add up all the arguments
// passed to a function
for (i=0; i<arguments.length; i++){
var sum = sum + arguments[i];
}
console.log(sum);
}
// You can now add as many numbers as you like
@Ajax30
Ajax30 / addargs2.js
Created November 23, 2016 19:09
Add the arguments passed to a function 2
function add(){
// Create an array from the functions arguments object
// then sum the array members using reduce
var sum = Array.from(arguments).reduce(function(a, b){
return a + b;
});
console.log(sum);
}
// You can now add as many numbers as you like
// just by passing them to the function
@Ajax30
Ajax30 / factorial.js
Last active November 28, 2016 08:05
Calculate the factorial of a number passed as the single parameter of a function
function fact() {
arr = [];
var n = arguments[0];
if (n == 0) {
arr.push(1);
} else {
for (i = 1; i <= n; i++) {
arr.push(i);
}
}
function addArrayMembers(arr) {
sum = 0;
arr.forEach(function(el, index) {
return sum = sum + arr[index];
});
return sum;
}
var arr = [1, 3, 5, 7];
addArrayMembers(arr);
<?php
try {
$con = new PDO('mysql:host=127.0.0.1;dbname=db_name','db_user','myPass');
} catch (PDOException $e) {
die("Database connection failed.");
}
?>
@Ajax30
Ajax30 / pdo_fetch_assoc.php
Last active July 16, 2018 15:39
Use PDO fetch method to display table rows
<?php
$sql = 'SELECT * FROM people';
$result = $db->query($sql);
$numrows = $result->rowCount();
?>
<table>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Gender</th>
@Ajax30
Ajax30 / Database
Last active October 2, 2018 07:24
Database class mysqli object oriented
<?php
class Database
{
public $host = DB_HOST;
public $username = DB_USER;
public $password = DB_PASS;
public $dbname = DB_NAME;
public $link;
public $error;
// Enter Mongo
Access `C:\Program Files\MongoDB\Server\4.2\bin` via CMD
// Enter mongo mode
mongo
// Show databases
show dbs
// Create and switch to database