Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / first-unique-character.js
Created April 6, 2017 23:02
Find the first unique character in a string.
/**
* @param {string} s
* @return {number}
*/
var firstUniqChar = function(s) {
var result = -1;
var hash = {};
for (var i=0; i<s.length; i++) {
if (hash[s[i]]) {
@primaryobjects
primaryobjects / Code.gs
Last active January 16, 2023 16:48
Export a Google Drive spreadsheet to PDF in Google Drive in the same folder.
// Simple function to add a menu option to the spreadsheet "Export", for saving a PDF of the spreadsheet directly to Google Drive.
// The exported file will be named: SheetName and saved in the same folder as the spreadsheet.
// To change the filename, just set pdfName inside generatePdf() to something else.
// Running this, sends the currently open sheet, as a PDF attachment
function onOpen() {
var submenu = [{name:"Save PDF", functionName:"generatePdf"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu('Export', submenu);
}
@primaryobjects
primaryobjects / capital.cpp
Created March 28, 2017 02:44
Detect correct capital letters in a word.
class Solution {
private:
bool isCapital(char ch) {
return ((int)ch >= 65 && (int)ch <= 90);
}
public:
bool detectCapitalUse(string word) {
bool result = true;
bool foundLower = false;
@primaryobjects
primaryobjects / binaryTree-max-depth.js
Created March 24, 2017 21:40
Finding the maximum depth of a binary tree in JavaScript.
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number}
class Hello extends React.Component {
constructor(props) {
super(props);
this.state = {
name: null,
count: 0
};
this.onChange = this.onChange.bind(this);
@primaryobjects
primaryobjects / index.html
Created March 13, 2017 14:41
Center element over clicked element in angularjs. Demo at http://jsbin.com/nimalut/edit?html,css,js,output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
@primaryobjects
primaryobjects / angular.html
Last active April 17, 2022 03:47
Rendering a JSONP REST API in a Bootstrap table using React, AngularJs, and jQuery.
<!-- Demo at http://jsbin.com/zejuvo/1/edit?html,js,output -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
@primaryobjects
primaryobjects / larrys-array.js
Created March 6, 2017 01:53
Left rotate 3 consecutive numbers in an array until the array is sorted.
function getInvalidCount(arr) {
// Count the number of invalid positions in a sorted array.
var result = 0;
for (var i=0; i<arr.length; i++) {
if (arr[i] !== i+1) {
result++;
}
}
@primaryobjects
primaryobjects / 1-rounding-grades.js
Created March 4, 2017 03:20
Rounding student grades to the next multiple of 5.
/* Method 1: Calculate the next multiple of 5 from the grade.
Do this by getting the tens digit of the grade, and then determining if +5 or +10 is closer to the grade.
Then simply calculate the difference and add to the grade.
O(1)
*/
function main() {
var n = parseInt(readLine());
for(var a0 = 0; a0 < n; a0++){
var grade = parseInt(readLine());
@primaryobjects
primaryobjects / linked-list-sorted-insert.java
Created March 4, 2017 02:51
Insert a node into a sorted linked list.
/*
Insert Node at the end of a linked list
head pointer input could be NULL as well for empty list
Node is defined as
class Node {
int data;
Node next;
Node prev;
}
*/