Skip to content

Instantly share code, notes, and snippets.

View yansusanto's full-sized avatar
:octocat:
Hustling

Yan Susanto yansusanto

:octocat:
Hustling
View GitHub Profile
class Top_Bar_Walker extends Walker_Nav_Menu {
function start_lvl( &$output, $depth = 0, $args = array() ) {
$output .= "\n<ul class=\"sub-menu dropdown\">\n";
}
function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
$item_html = '';
parent::start_el( $item_html, $object, $depth, $args );
$output .= ( $depth == 0 ) ? '<li class="divider"></li>' : '';
@yansusanto
yansusanto / default.vcl
Created September 9, 2014 13:35
WordPress 4.0 + Varnish 3.0
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"127.0.0.1";
"localhost";
}
export const squareImage = graphql`
fragment squareImage on File {
childImageSharp {
fluid(maxWidth: 520, maxHeight: 400) {
...GatsbyImageSharpFluid
}
}
}
`;
import { useState, useLayoutEffect } from 'react';
export const useWindowWidth = () => {
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
const handleWindowResize = () => {
setWindowWidth(window.innerWidth);
};
useLayoutEffect(() => {
@yansusanto
yansusanto / new Date();
Last active July 22, 2020 13:34
Set a date 12 months in the future
const oneYearLater = new Date(
new Date().getFullYear(),
new Date().getMonth() + 12,
new Date().getDate()
);
let launchDate = oneYearLater;
@yansusanto
yansusanto / ScrollTo()
Last active July 25, 2020 04:15
Smooth scrolling in Vanilla JS
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener("click", (e) => {
e.preventDefault();
document.querySelector(anchor.getAttribute("href"))
.scrollIntoView({
behavior: "smooth",
block: "start",
});
});
});

Install bootstrap

npm install react-bootstrap bootstrap

Install Sass

npm install node-sass gatsby-plugin-sass

Set up Bootstrap scss

  • Download source files from getbootstrap.com and copy the scss directory to src/scss/bootstrap
  • Configure gatsby-plugin-sass, specifying the bootstrap scss directory created in porevious step:
import React, { Component } from 'react';
import { StyleSheet, View, Animated, Easing, Text, Image, AppState } from 'react-native';
import PropTypes from 'prop-types';
import { RNCamera } from 'react-native-camera';
const defaultRectStyle = { height: 300, width: 300, borderWidth: 0, borderColor: '#000000', marginBottom: 0 };
const defaultCornerStyle = { height: 32, width: 32, borderWidth: 3, borderColor: '#1dbc60' };
const defaultScanBarStyle = { marginHorizontal: 8, borderRadius: 2, backgroundColor: '#1dbc60' };
const defaultHintTextStyle = { color: '#aaa', fontSize: 14, backgroundColor: 'transparent', marginTop: 32 };
const randomString = () => Math.random().toString(36).slice(2);