Skip to content

Instantly share code, notes, and snippets.

View KeithNdhlovu's full-sized avatar

Keith Ndhlovu KeithNdhlovu

View GitHub Profile
@KeithNdhlovu
KeithNdhlovu / kaggle_download.py
Created August 18, 2022 08:57 — forked from jayspeidell/kaggle_download.py
Sample script to download Kaggle files
# Info on how to get your api key (kaggle.json) here: https://github.com/Kaggle/kaggle-api#api-credentials
!pip install kaggle
api_token = {"username":"USERNAME","key":"API_KEY"}
import json
import zipfile
import os
with open('/content/.kaggle/kaggle.json', 'w') as file:
json.dump(api_token, file)
!chmod 600 /content/.kaggle/kaggle.json
!kaggle config path -p /content
@KeithNdhlovu
KeithNdhlovu / Final implementation.js
Last active July 10, 2020 11:50
Implementation of the Page Visibility API and Browser idle state detection
export default class MainLayout extends Component {
constructor() {
super()
window.idleTime = 0
window.idleInterval = null
}
// Instance of Ad
var banner = new Ad(params)
// Set the name of the hidden property and the change event for visibility
var hidden, visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.msHidden !== "undefined") {
@KeithNdhlovu
KeithNdhlovu / HouseDoor.cs
Created March 1, 2019 10:55
Unity Transition between animations, in this case we have a case where we need to open the door when the right mouse is clicked pointing to the door
using UnityEngine;
using System.Collections;
public class HouseDoor : MonoBehaviour {
public Animation doorOpenAnimation;
public Animation doorCloseAnimation;
public bool doorOpen= false;
@KeithNdhlovu
KeithNdhlovu / example.html
Last active July 20, 2017 08:35
Angular JS Directives for Google map with place picker and on pin drag callback update position and Geocode address from location
<!-- [ You obviously need google maps] -->
<script type="text/javascript" src='https://maps.google.com/maps/api/js?key=[ "The secret key here" ]&libraries=places'></script>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#gmaps {
width: 100%;
height: 200px;
}
@KeithNdhlovu
KeithNdhlovu / initLoader.js
Created June 5, 2017 09:46
Just a custom SVG loader animation
/**
* SVG Loader
* @template: '<div class="main-loader center" ng-show="showLoader"></div>'
*/
var Paper = Snap(".main-loader");
if (Paper !== null) {
Snap.load("loader.svg", function ( f ) {
Paper.append( f );
@KeithNdhlovu
KeithNdhlovu / index.html
Last active March 30, 2017 09:32
This Function will Create a RadarChart/SpiderChart/Line Chart/Bar Chart/Line And Bar
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0" />
<title>Starter Template - Materialize</title>
<!-- CSS -->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
/**
* Generates a color between green and red to specify the risk of the compliance.
*
* @param percentage value Will be used to calculate risk.
* @return Risk color.
*/
$scope.rangeColor = function(pct) {
var percentColors = [
{ pct: 0, color: { r: 0xff, g: 0x00, b: 0 } },
{ pct: 50, color: { r: 0xff, g: 0xff, b: 0 } },
@KeithNdhlovu
KeithNdhlovu / isItMe.js
Created March 24, 2017 17:11
Checks if the item you clicked on, is anything except for itself
$(document).click(function(e) {
var target = e.target;
if (!$(target).is('#menu') && !$(target).parents().is('#menu')) {
$('#menu').hide();
}
});
@KeithNdhlovu
KeithNdhlovu / AngularInputFile.js
Created February 13, 2017 10:24
How to attach ng-model on an input type=file
var clientInformationApp = angular.module('clientInformationApp', [], function($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
}).directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {