Skip to content

Instantly share code, notes, and snippets.

View udnisap's full-sized avatar

Pasindu Perera udnisap

View GitHub Profile
@udnisap
udnisap / xPathGetter
Last active August 29, 2015 13:59
xPathGetter
if (typeof xpathGetter === 'undefined') {
xpathGetter = function(){
var isActive = false,
mode = "XPATH";//0 - xpath, 1-css, 2-id
version = "0.1",
codeTemplate = null,
iniatilized = false;
var pub = {};
var self = {
var codeTemplate = '\
\
<ul class="people_list"> \
{{#each people}} \
<li>{{this}}</li> \
{{/each}} \
</ul> \
\
';
$con = mysqli_connect ( $MYSQL_HOSTNAME, $MYSQL_USERNAME, $MYSQL_PASSWORD, $MYSQL_DATABASE );
$tables = array ();
$result = mysqli_query ( $con, 'SHOW TABLES' );
while ( $row = mysqli_fetch_array ( $result ) ) {
$tables [] = $row [0];
}
// cycle through the tables
foreach ( $tables as $table ) {
@udnisap
udnisap / rate_limit.js
Last active November 9, 2019 16:49 — forked from epogue/rate_limit.js
This will make sure(most of the times) the concurrent invocation is handled
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request
const API = 'https://jsonplaceholder.typicode.com';
// Data Fetching and Logic
const getData = (endpoint) =>
fetch(`${API}/${endpoint}`)
.then(resp => resp.json());
const findUserByUserName = (username) =>
getData(`users?username=${username}`)
@udnisap
udnisap / gist:d82f40b3066af5e3f22a763d5ce317c8
Last active November 27, 2016 16:38
Format a Hard disk with DD
# To Display disk mapping
lsblk
# Erase the disk with random strings
dd if=/dev/urandom of=/dev/null status=progress
// main function
customers = readFile('customer.dat');
prefCustomers = readFile('preffrred.dat')
orders = readFile('orders.dat')
for (order in orders){
customer = order.getCustomer();
subtotal = order.calcuateTotal();
currentAmountSpent = customer.getAmountSpent;
a) Create a simple ReactJS front end in JS Fiddle using the Star Wars API https://swapi.co/
b) List all the films in first page
c) List all the Characters in a film when you click on a film
d) Bonus points if you use React with Redux/Flux
e) Make sure your front end is responsive
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script>
let data = [1,10,4,5,3,5,1,4,5];
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.3.0/jasmine.js"></script>