Skip to content

Instantly share code, notes, and snippets.

View koyanloshe's full-sized avatar
👁️
Focusing

Alok Shenoy koyanloshe

👁️
Focusing
View GitHub Profile
@koyanloshe
koyanloshe / commands.sh
Last active April 17, 2020 08:31
Static site generator #Javascript #Unix
// Step 1: Clone repository from GitHub
$ git clone https://github.com/ericalli/static-site-boilerplate
&& cd static-site-boilerplate && rm -rf .git && git init
// Step 2: Install dependencies
$ npm install
// Step 3: Run the development server
$ npm run start
// Step 4: Generate production-ready files
$ npm run build:dist
@koyanloshe
koyanloshe / foundation.js
Last active April 17, 2020 08:32
Foundation equaliser #Javascript
/*
* This is a JavaScript Scratchpad.
*
* Enter some JavaScript, then Right Click or choose from the Execute Menu:
* 1. Run to evaluate the selected text (Cmd-R),
* 2. Inspect to bring up an Object Inspector on the result (Cmd-I), or,
* 3. Display to insert the result in a comment after the selection. (Cmd-L)
*/
(function webpackUniversalModuleDefinition(root,factory){if(typeof exports==='object'&&typeof module==='object')
@koyanloshe
koyanloshe / smooth scroll jQuery snippet
Last active April 17, 2020 08:28
smoothScroll.js #Javascript #jQuery
$("a").on('click', function (event) {
if (this.hash !== "") {
event.preventDefault();
var hash = this.hash;
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function () {
window.location.hash = hash;
});
};
@koyanloshe
koyanloshe / function for trigger event
Last active December 13, 2018 07:08
Trigger an event in plain.JS #Javascript
function triggerEvent(el, type) {
if ('createEvent' in document) {
// modern browsers, IE9+
var e = document.createEvent('HTMLEvents');
e.initEvent(type, false, true);
el.dispatchEvent(e);
} else {
// IE 8
var e = document.createEventObject();
e.eventType = type;
@koyanloshe
koyanloshe / boilerplate.html
Last active April 17, 2020 08:30
Emailer boilerplate interactive demo by Litmus #HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
lang="en" xml:lang="en">
<head>
<title>Interactive Email Elements</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
@koyanloshe
koyanloshe / path issue Babel
Created November 23, 2018 07:34
Babel #Path #npm
export PATH=$PATH:/Users/koyanloshe/.npm-packages/bin
@koyanloshe
koyanloshe / beforeIntersectionObeserver.js
Last active April 17, 2020 08:32
Check if a certain element in the viewport #Javascript
function onVisibilityChange(el, callback) {
var old_visible;
return function () {
var visible = isElementInViewport(el);
if (visible != old_visible) {
old_visible = visible;
if (typeof callback == 'function') {
callback();
}
}
# clone repo
git clone https://github.com/Microsoft/vscode-react-sample.git react-todo
# navigate to repo
cd appFolderName
# install deps
npm install
# Run in terminal backend
@koyanloshe
koyanloshe / telnet setup
Last active April 17, 2020 08:29
Chat Server #Javascript
var net = require('net')
var chatServer = net.createServer(), clientList = []
chatServer.on('connection', function(client) {
client.name = client.remoteAddress + ':' + client.remotePort client.write('Hi ' + client.name + '!\n');
clientList.push(client)
client.on('data', function(data) { broadcast(data, client)
}) })
function broadcast(message, client) { for(var i=0;i<clientList.length;i+=1) {
if(client !== clientList[i]) { clientList[i].write(client.name + " says " + message)
} }
@koyanloshe
koyanloshe / killall.sh
Last active April 17, 2020 08:30
Kill a node server process that wont terminate #Unix
//primary attempt
killall node
//secondary attempt
kill -9 $(ps aux | grep '\snode\s' | awk '{print $2}')