Skip to content

Instantly share code, notes, and snippets.

View tinshade's full-sized avatar
🔥
Persevere

Abhishek Iyengar tinshade

🔥
Persevere
View GitHub Profile
@tinshade
tinshade / html_for_international_calling coes.htm
Created September 2, 2018 12:19 — forked from robsonvn/html_for_international_calling coes.htm
HTML <select> international calling codes for each country
<!-- using semantic ui to display flags -->
<div class="field">
<label>Country</label>
<div class="ui fluid search selection dropdown">
<input type="hidden" name="country" value="">
<i class="dropdown icon"></i>
<div class="default text">Select Country</div>
<div class="menu">
<div class="item" data-value="64"><i class="nz flag"></i>New Zealand (+64)</div>
<div class="item" data-value="61"><i class="au flag"></i>Australia (+61)</div>
@tinshade
tinshade / quizzizScript.js
Created October 15, 2020 03:25
The annoying quizziz questions will not survive any longer. OCT 2020 edition
// First we want to detect if the URL is valid
if (window.location.href.search("quizizz.com/join/game/") == -1 && window.location.href.search("gameType=") == -1) {
throw new Error("You aren't on a quizizz quiz. If you think this is an error please DM East_Arctica#9238 on discord!");
}
if (typeof jQuery == 'undefined') {
let script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.4.1.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
@tinshade
tinshade / LocalOrServer
Created October 16, 2020 14:00
PHP code to check if you are on LocalHost or On the Server. Mostly useful to switch between local and server DB without changing the config file too often.
<?php
$whitelist = array('127.0.0.1','::1');
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
echo 'Not Whitelisted<br/>'.$_SERVER['REMOTE_ADDR'];
}else{
echo 'Whitelisted<br/>'.$_SERVER['REMOTE_ADDR'];
}
?>
@tinshade
tinshade / pagination.php
Created October 17, 2020 09:09
Simple pagination boilerplate using PHP and MySQL Database.
<html>
<head>
<title> Pagination </title>
</head>
<body>
<?php
//database connection
$conn = mysqli_connect('localhost', 'root', '', 'db_name');
@tinshade
tinshade / PHPReadWriteFilesToDirectory.php
Created October 17, 2020 12:51
I just wanted to write a file to the directory and read it via JS for a very particular use-case. Here's the script if you know what you're doing.
<?php
$conn = mysqli_connect('localhost', 'root', '', 'db_name');
$row = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM table_name"));
if(!$conn){
echo 'Nope, dead.';
}else{
$myfile = fopen("filename.txt", "w+");
$txt = strval($row['index']);
fwrite($myfile, $txt);
fclose($myfile);
@tinshade
tinshade / PFTP.py
Created October 22, 2020 14:00
Creating a FTP server with Python3 and transferring files.
#Start a server with: python -m pyftpdlib -p 21 -w --user="some_username" --password="some_password"
#Works for python3.x, didn't test for python2.x
import ftplib #Built-in library
session = ftplib.FTP('127.0.0.1', 'some_username' ,'some_password')
file = open('<filename with extension>','rb') # file to send
session.storbinary('STOR <recieved file name with extension>', file) # send the file
file.close() # close file and FTP
@tinshade
tinshade / smooth.js
Created October 25, 2020 08:42
Get that smooth scroll rolling from your navbar to a section on your page/across all pages. Just include this after your jQuery.
$(function () {
$(window).on('scroll', function () {
if ( $(window).scrollTop() > 10 ) {
$('.navbar').addClass('active');
} else {
$('.navbar').removeClass('active');
}
});
});
@tinshade
tinshade / RunningEXEViaNodeJS.js
Created October 27, 2020 07:37
Here's as small script to run an external EXE using NodeJS. I used this to run a dependency EXE from my ElectronJS application.
function runExternal(){
var execFile = require('child_process').execFile, child;
//The `process.cwd()` //Gets the current working directory.
//Just writing the name of the exe file and being in the same directory does not work!
child = execFile(process.cwd()+'nameofexe.exe', function(error,stdout,stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+ error.code);
console.log('Signal received: '+ error.signal);
}else{
@tinshade
tinshade / MyPythonScript.py
Created October 27, 2020 10:11
Here's my script on running a python script right from your NodeJS application without spinning an express server!
# This script will create a file with the name and extenstion provided in the parameters.
# Not very useful but the simplest example I could think of
import os, sys
path = os.getcwd()+"\\custom_path\\"+sys.argv[1] # I needed a custom path, you can omit that part. You still need the absolute path.
open(path,'w+') #Works like a native charm!
print("Done") #You will get this in the STDOUT on your Node console.
@tinshade
tinshade / WebcamWithJS.html
Created October 28, 2020 04:29
Here's how you can capture images via the webcam from a webpage. This also displays the captured images in a stateless manner.
<!doctype html>
<head>
<style>
/* CSS comes here */
#video {
border: 1px solid black;
width: 320px;
height: 240px;
}