Skip to content

Instantly share code, notes, and snippets.

View afzafri's full-sized avatar
🎯
Focusing

Afif Zafri afzafri

🎯
Focusing
View GitHub Profile
@afzafri
afzafri / script.js
Created November 28, 2017 02:03
jquery clone select box on change
$(document).ready(function () {
$(document).on('change','#sel',function(){
$(this).clone().appendTo('#cloneTarget').after('<br>');
$('select:last').focus();
$('#selectedVal').append($(this).val()+"<br>");
});
});
@afzafri
afzafri / mocking.py
Created May 30, 2017 15:23
Mocking Spongebob text generator. Simple script to generate alternating uppercase and lowercase text.
import sys
if len(sys.argv) < 2:
print "Usage: python mocking.py <text>"
else:
text = str(sys.argv[1]).lower()
for i in range(len(text)):
sys.stdout.write((i%2==0) and text[i].upper() or text[i])
@afzafri
afzafri / recursive_fib.py
Created March 29, 2017 01:53
Just an example of recursive function. For my future references.
def genFib(a,b,i):
if i == 10:
return 0
c = b + a
a = b
b = c
print(c)
i = i + 1
genFib(a,b,i)
@afzafri
afzafri / primesieve.py
Last active March 23, 2017 15:39
Finding the Prime Numbers up to any limit using Sieve of Eratosthenes algorithm. Code example in Python
import time
start_time = time.clock()
# using Sieve of Eratosthenes algorithm
limit = 10000000
# set objects is more faster
not_primenums = set()
primes = set()
print "Generate prime numbers under ", limit
@afzafri
afzafri / cordovaAjaxLogin.js
Created March 12, 2017 14:14
JS Code snippet for Ajax login function for Cordova/Hybrid apps
// login function
function ajaxLogin(params)
{
$.ajax({
url: APIUrl+'/login',
type: 'post',
dataType: 'json',
data: params,
success: function(data) {
@afzafri
afzafri / fastsum.py
Created February 12, 2017 03:18
Efficient and Fast formula for Sum of numbers. Just a for future references
maxnum = int(raw_input('Enter limit number: '))
sum = ((maxnum+1)*maxnum) / 2
print(sum)
@afzafri
afzafri / ImagePixelCoordinate.html
Last active May 27, 2021 14:17
Image Pixel Coordinate Generator. A simple Javascript web application for my Smartwatch Watch Face website, use to find the pixel coordinate in a photo, for watch face making purpose.
<p>Choose your clock_bg Photo</p>
<!-- choose image file, on choose, automatically set to the canvas -->
<input type="file" id="imageLoader" name="imageLoader"/>
<!-- hide the tool, only show once file is choosen -->
<div id="toolArea" style="display: none;">
<p>Click on the image to place a marker<br> The markers on the image will show the coordinates value in decimal, while the table below will show the coordinates in Hex value.</p>
<!-- draw image and markers on the canvas here -->
<canvas id="Canvas" width="240" height="240"></canvas>
@afzafri
afzafri / infinitescroll.html
Last active January 10, 2017 13:21
My own simple jquery infinite scrolling, to be used in future project with ajax
<!DOCTYPE html>
<html>
<head>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<title>Infinite Scroll Test</title>
</head>
<body>
@afzafri
afzafri / fbpostscrape.php
Last active March 31, 2023 20:15
Fetch/Scrape Facebook Page posts contents without using Facebook API
<?php
/* Facebook Page Posts Scrapper API created by Afif Zafri.
Fetch/Scrape posts contents of a page without using Facebook API
Usage: http://site.com/api.php?username=CODE , where CODE is the page username
*/
if(isset($_GET['username']))
{
@afzafri
afzafri / datatabledemo.php
Last active May 16, 2023 10:57
Example usage of DataTables jQuery table plugin with Bootstrap
<!DOCTYPE html>
<html>
<head>
<title>Datatables Study Demo</title>
<!-- jQuery -->
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>