Skip to content

Instantly share code, notes, and snippets.

View MariaSzubski's full-sized avatar

Maria Szubski MariaSzubski

View GitHub Profile
@MariaSzubski
MariaSzubski / react-toggle.js
Created September 12, 2019 15:01
React Hook - toggle Menu with outside click
const ToggleMenu = props => {
const [isOpen, setOpen] = useState(false)
const toggleNav = () => setOpen(!isOpen)
const nodeRef = useRef()
useEffect(() => {
const handleOutsideClick = e => {
if (!nodeRef.current.contains(e.target)) {
toggleNav()
@MariaSzubski
MariaSzubski / react_object.js
Created June 6, 2018 15:35
React - Using an object to set multiple img properties
const pics = {
panda: "http://bit.ly/1Tqltv5",
owl: "http://bit.ly/1XGtkM3",
owlCat: "http://bit.ly/1Upbczi"
};
const panda = (
<img
src={pics.panda}
alt="Lazy Panda" />
npm install webpack --save-dev
# install webpack for dev env only
@MariaSzubski
MariaSzubski / px_rem.js
Created October 2, 2017 04:26
Use <button> to convert between pixel and rem units. Setting applies site-wide.
/*
Requires html button with at least two unit options.
Unit setting is saved in local storage.
*/
// PX to REM Conversion
if (Modernizr.localstorage) {
// ----------------- On initial load: check local storange and convert units
toggle_pxrem();
@MariaSzubski
MariaSzubski / git_cheatsheet.sh
Last active January 22, 2018 17:24
Useful git commands
log/diff --stat
# diagram of changes per file
log/diff --shortstat
# count of changes
log --oneline
# sha + commit messages
shortlog
@MariaSzubski
MariaSzubski / working_directory.bash
Last active March 20, 2018 14:03
Terminal Prompt: Working Directory Basename
# Startup command to set terminal prompt to working directory basename
export PS1="\[\033[38;5;116m\]\W \$\[\033[00m\] "; clear; cd [path/to/working_directory]
# working_directory $
@MariaSzubski
MariaSzubski / rotateArray.js
Created September 1, 2016 03:23
John Watson performs an operation called a 'right circular rotation' on an array of integers. Find the element at index 'm' in the rotated array.
/*
Solution for HackerRank > Algorithms > Warmup > Circular Array Rotation
https://www.hackerrank.com/challenges/circular-array-rotation
*/
function sherlock() {
// Number of rotations
var k = 51;
// Array of Integers
var arr = [39356, 87674, 16667, 54260, 43958, 70429, 53682, 6169, 87496, 66190, 90286, 4912, 44792, 65142, 36183, 43856, 77633, 38902, 1407, 88185, 80399, 72940, 97555, 23941, 96271, 49288, 27021, 32032, 75662, 69161, 33581, 15017, 56835, 66599, 69277, 17144, 37027, 39310, 23312, 24523, 5499, 13597, 45786, 66642, 95090, 98320, 26849, 72722, 37221, 28255, 60906];
@MariaSzubski
MariaSzubski / cutSticks.js
Last active February 11, 2025 12:28
Given N sticks, reduce the length of each by the length of the smallest stick. Print the number of sticks that are left before each cut operation.
/*
Solution for HackerRank > Algorithms > Implementation > Cut The Sticks
https://www.hackerrank.com/challenges/cut-the-sticks
*/
function cutSticks() {
var n = 8; // Number of sticks
arr = [1,2,3,4,3,3,2,1]; // Stick length
while (arr.length > 0){
@MariaSzubski
MariaSzubski / kangaroos.js
Last active September 1, 2016 04:32
Compare two equations to see if they are ever equal. #congruence #Hackerrank
/*
Solution for HackerRank > Algorithms > Implementation > Kangaroo
https://www.hackerrank.com/challenges/kangaroo
In this example, 0 <= x1 <= x2
*/
function kangaroos() {
var x1 = 43;
var v1 = 5;
@MariaSzubski
MariaSzubski / patternRemoval.js
Last active July 21, 2016 22:25
Swap a substring to remove '010' pattern. #hackerrank #strings
/*
Solution for HackerRank > Algorithms > Strings > Beautiful Binary String
https://www.hackerrank.com/challenges/beautiful-binary-string
*/
function main(){
var B = '0100101010';
var stepCount = 0;
// While the substring '010' exists, replace it with '011'.