Skip to content

Instantly share code, notes, and snippets.

View completejavascript's full-sized avatar

Lam Pham completejavascript

View GitHub Profile
@completejavascript
completejavascript / service-worker-sample.js
Created January 12, 2018 02:35
Basic sample of Service Worker
/*
Copyright 2016 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
@completejavascript
completejavascript / netctl-configure-dhcp-arch-linux
Created January 10, 2018 02:36
Configuration a DHCP connection in Arch Linux
# Copying the /etc/netctl/examples/ethernet-dhcp example profile to /etc/netctl.
Interface=enp3s0
Connection=ethernet
IP=dhcp
@completejavascript
completejavascript / active-network-interface-manually-arch-linux
Created January 10, 2018 02:34
Enabling and disabling network interfaces in Arch Linux
# You can activate a network interface using:
ip link set <interface> up
Example:
ip link set enp0s3 up
# To deactivate it do:
ip link set <interface> down
Example:
ip link set enp0s3 down
@completejavascript
completejavascript / install-certificate-ubuntu
Created January 4, 2018 03:57
Install Certificate on Ubuntu
# Installing a root/CA Certificate
# Given a CA certificate file foo.crt, follow these steps to install it on Ubuntu:
# Create a directory for extra CA certificates in /usr/share/ca-certificates:
sudo mkdir /usr/share/ca-certificates/extra
#Copy the CA .crt file to this directory:
sudo cp foo.crt /usr/share/ca-certificates/extra/foo.crt
#Let Ubuntu add the .crt file's path relative to /usr/share/ca-certificates to /etc/ca-certificates.conf:
sudo dpkg-reconfigure ca-certificates
@completejavascript
completejavascript / install-gcc-g++-ubuntu-14.04
Created January 4, 2018 02:26
Install gcc & g++ 5.x on Ubuntu 14.04
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-5
sudo rm -f /usr/bin/gcc
sudo rm -f /usr/bin/g++
sudo ln -s /usr/bin/gcc-5 /usr/bin/gcc
sudo ln -s /usr/bin/g++-5 /usr/bin/g++
@completejavascript
completejavascript / overlay-toggle-menu-index.html
Last active January 26, 2018 08:30
Simple Overlay Toggle Menu using jQuery
<div class="container">
<a href="#" class="toggle-menu">Toggle Menu</a>
<div class="overlay hidden">
<ul>
<li>
<a href="#">Menu 1</a>
</li>
<li>
<a href="#">Menu 2</a>
</li>
@completejavascript
completejavascript / smooth-scrolling.js
Created February 23, 2018 15:53
Smooth scrolling using jQuery
// Smooth scrolling
$("a[href*='#']:not([href='#'])").click(function () {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
|| location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
@completejavascript
completejavascript / grid.css
Last active February 23, 2018 15:54
A Responsive Design CSS Library
/* The padding and border are included in the total width and height of the elements. */
* {box-sizing: border-box;}
/* Mobile first */
/* Define width of col- */
.gr-col-xs-1 {width: 8.33%;}
.gr-col-xs-2 {width: 16.66%;}
.gr-col-xs-3 {width: 25%;}
.gr-col-xs-4 {width: 33.33%;}
.gr-col-xs-5 {width: 41.66%;}
@completejavascript
completejavascript / isInViewPort.js
Created February 23, 2018 16:15
Check whether element is in viewport
function isInViewPort(element){
let elementTop = $(element).offset().top;
let elementBottom = elementTop + $(element).outerHeight();
let viewPortTop = $(window).scrollTop();
let viewPortBottom = viewPortTop + $(window).height();
return elementBottom > viewPortTop && elementTop < viewPortBottom;
}
@completejavascript
completejavascript / setHashLocation.js
Created February 23, 2018 16:16
Set hash location for url address
// Set hash location for url address
function setHashLocation(id) {
var scrollmem = $('html,body').scrollTop();
window.location.hash = id;
$('html,body').scrollTop(scrollmem);
}