This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getMousePosition = (e) => { | |
let posX = 0, posY = 0; | |
if (!e) e = window.event; | |
if (e.pageX ¦¦ e.pageY) { | |
posX = e.pageX; | |
posY = e.pageY; | |
} | |
// This only applies in IE | |
else if (e.clientX ¦¦ e.clientY) { | |
const eventDoc = (e.target && e.target.ownerDocument) ¦¦ document; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import https module for making API calls | |
const https = require('https') | |
// import querystringify to construct a query from an object | |
const qs = require('querystringify') | |
const consumerApiKey = YOUR_CONSUMER_API_KEY | |
const apiSecretKey = YOUR_API_SECRET_KEY | |
const plainCredential = `${consumerApiKey}:${apiSecretKey}` | |
const bearerToken = Buffer.from(plainCredential).toString('base64') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Tested on Robby Russell theme, and Python and Node programs. | |
- Duplicate the current theme you are using and copy it to .oh-my-zsh/custom/themes. | |
For example, if you're using Robby Russell, the custom file should also be robbyrussell.zsh-theme. | |
- Paste the following code at the end of the custom file to override some parts of the current them.e | |
*/ | |
function program_prompt_version() { | |
# $1 is the name of the program, e.g. python, node. | |
# $2 is the command used to get the version of the program. For Node, it's `-v`. For Python, it's `-V`. | |
if which $1 &> /dev/null; then | |
local version=$($1 -$2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.4.12) | |
// Compass (v1.0.3) | |
// ---- | |
$scotch-color-key: 'base' !default; | |
$scotch-colors: ( | |
'primary': ( | |
'base': #8e3329, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@use "sass:color"; | |
@function replaceString($string, $target, $replace: '_') { | |
// Find index of the character to be replaced | |
$index: str-index($string, $target); | |
@if $index { | |
@return str-slice($string, 1, $index - 1) + $replace + str-slice($string, $index + 1); | |
} | |
// If the target character is not part of the string, just return the whole string | |
@else { | |
@return $string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--spacing__base_unit: 16px; | |
--spacing__unit--0_25: calc(var(--spacing__base_unit) * 0.25) ; | |
--spacing__unit--0_5: calc(var(--spacing__base_unit) * 0.5) ; | |
--spacing__unit--0_75: calc(var(--spacing__base_unit) * 0.75) ; | |
--spacing__unit--1: calc(var(--spacing__base_unit) * 1) ; | |
--spacing__unit--1_5: calc(var(--spacing__base_unit) * 1.5) ; | |
--spacing__unit--2: calc(var(--spacing__base_unit) * 2) ; | |
--spacing__unit--3: calc(var(--spacing__base_unit) * 3) ; | |
--spacing__unit--4: calc(var(--spacing__base_unit) * 4) ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@use "sass:string"; | |
:root { | |
--background-standard: #fff; | |
} | |
@function rem($px, $base: 16) { | |
@return $px / $base; | |
}; | |
@function rem-to-px($rem, $base: 16) { | |
@return $base * $rem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Suppose we have an array [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]. | |
Given number is 4 at index 3. | |
How to find the 5th number from the given number above going backwards? | |
Result should be 11. Note that once our loop reaches the beginning of the array, we will continue to loop from the end | |
going backwards. | |
*/ | |
function findElem(arr, givenIndex, offset) { | |
const subtract = givenIndex - offset; | |
let cur; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Divide screen width into five broad groups. | |
$mediaXL: 1200px; | |
$mediaLarge: 992px; | |
$mediaMedium: 768px; | |
$mediaSmall: 576px; | |
$mediaExtraSmall: 480px; | |
/* Thanks 3rdthemagical for sharing the helper function for converting string to number. | |
This is useful when we want to pass a custom device width that's different from any of the options above. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Example: Search for all files in Google Drive whose file names contains the word 'tracker'. The result would be: | |
- Fitness tracker | |
- Personal finance tracker | |
- Job application tracker | |
*/ | |
function searchFiles(name) { | |
var results = []; | |
var query = `title contains "${name}"`; | |
var files = DriveApp.searchFiles(query); |
NewerOlder