Skip to content

Instantly share code, notes, and snippets.

View PantherHawk's full-sized avatar

Alexander Rosenthal PantherHawk

View GitHub Profile
@PantherHawk
PantherHawk / FloatingShvitiExperience.js
Created May 25, 2021 22:57
Use of React Three Fiber SVG Loader
import * as THREE from 'three';
import React, { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { Canvas, extend, useThree, useFrame } from 'react-three-fiber';
import flatten from 'lodash-es/flatten';
import { SVGLoader as loader } from 'three/examples/jsm/loaders/SVGLoader';
import SVG_SHVITI_URL from './Shviti.svg';
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
class UserHome(UserPagesMixin, ListView):
...
def post(self, request, *args, **kwargs):
print('----------we are in post------------')
if 'eshel' in request.POST:
if 'yes_eshel' in request.POST:
print("YES ESHEL")
instance = Settings.objects.get(pk=self.request.user)
@PantherHawk
PantherHawk / make-bank.sql
Created October 18, 2018 04:11
some sql to make a bank, just a way to save stuff
drop table users;
drop table role;
create table role
(id number primary key not null,
is_admin number not null);
create table users
(name varchar(20) not null,
passhash nvarchar2(20) not null,
id number(19, 0) not null,
@PantherHawk
PantherHawk / App.js
Created September 27, 2018 15:36
Assessment for Tophat
import React, { Component } from 'react';
import { imageSearch } from './api';
import './App.css';
const AppContext = React.createContext();
let timeOutId = 0;
export default class App extends Component {
constructor(props) {
super(props);
@PantherHawk
PantherHawk / archiving.md
Last active July 29, 2018 07:29
E-Mail Archiving Project 2018

E-Mail Archiving for Outlook v.20x+ on Windows

Problem: Inbox Inundation

E-mail, like everything else, goes the way of entropy. Left unchecked, an inbox will bloat and create a categorization nightmare. Although wrangling Outlook into a seemly and organized file system may feel like a Sisyphean task, we will approach step by step.

  • Backup the Inbox
  • Clean the .pst file (waiting on SCANPST.exe)
  • Archive Inbox
  • Customize Outlook
  • Compact Archive folder

Requirements

Return true if a singly linked list has a loop.

Strategy

Use two pointers, the second moving twice the speed of the first, and see if the two pointers ever land on the same node.

Justification of strategy

Consider two runners on a track. The faster runner will lap the slower one. The faster runner in our case is a pointer incremented douple the incrementation of the slower pointer.
The edge case we have to account for is when the slow or the fast or the immediate child of the fast node is null.

Define Test Cases

let linkedList = new LinkedList();

Requirements

Given a list of integers, return the number of times it takes produce a list of equal integers by incrementing n - 1 elements by one.

Strategy

Maths!

Justification of strategy

The largest number in the list, x, is greater than or equal to the product of s, the smallest number, 1, the number we increment the smallest number by, and m, the number of times we increment, and the value we're after. ![equation](x <= 1 * m) Refactoring, we find that the product of m and the number of elements we increment equals the difference between the sum of all elements and the product of the largest element and the number of elements. ![equation](m*(n-1) = sum-x*n >= sum-(minNum+m)n)

function minMoves(list) {
var sum = list.reduce((a, b) => a + b)
var minNum = Math.min(...list)
var n = list.length;
return sum-(minNum)*n
}

Requirements

Create a stack prototype with a method that returns the smallest value in constant time.

Strategy

Constructor has a push, pop, and get minimum value methods. Update the minimum value whenever we push or pop a value.

Justification of strategy

To get that sweet, sweet constant time look up for our minimum value, we have to compare the minimum value stored in our instance to any value we add, and then iterate through the stack to find a new smallest value whenever we pop.

Define test cases

  • push(3), push(2), getMin() should return 2
  • push(0 ... 500), getMin() should return 0
  • push(-2), push(-3), push(-5), pop(), getMin() should return -3
var MinStack = function() {
this.stack = [];
this.min;
};
MinStack.prototype.push = function(x) {
this.stack.push(x);
if (!this.min && this.min !== 0) {
this.min = x;
} else if (x < this.min) {