Skip to content

Instantly share code, notes, and snippets.

View earlonrails's full-sized avatar

Kevin Krauss earlonrails

  • Disney Streaming
  • San Francisco
View GitHub Profile
@earlonrails
earlonrails / timeConvert.js
Created February 9, 2017 20:04
Convert 12hr format to 24hr time format
#!/usr/bin/env node
"use strict"
class TimeConvert {
constructor(str, type = "regex", debug = false) {
if (debug) console.log("Original time: " + str)
this.str = str
this.type = type
this.debug = debug
}
@earlonrails
earlonrails / fibonacci.js
Created February 8, 2017 08:01
Standard fibonacci in javascript es6
#!/usr/bin/env node
"use strict"
let fib = function(n, memo={}) {
if (n < 2) return n
memo[n] = memo[n] || fib(n-2, memo) + fib(n-1, memo)
return memo[n]
}
for(var i=1; i < 11; i++) {
@earlonrails
earlonrails / depthFirstSearch.js
Created January 25, 2017 23:02
depth first search in javascript
#!/usr/bin/env node
"use strict"
// Create graph/tree type structure
class Node {
constructor(name) {
this._name = name
this._children = []
}
@earlonrails
earlonrails / isPrime.js
Created January 24, 2017 20:03
check if a number is prime in javascript
function isPrime(n) {
if (n <= 1) return false
var prime = true
var sqrtN = parseInt(Math.sqrt(n))
for (var i = sqrtN; i > 1; i--) {
if (n % i == 0) {
prime = false
break
}
}
// There are 2 non-negative integers: i and j. Given the following equation,
// find an (optimal) solution to iterate over i and j in such a way that the output is sorted.
// 2^i * 5^j
// So the first few rounds would look like this:
// 2^0 * 5^0 = 1
// 2^1 * 5^0 = 2
// 2^2 * 5^0 = 4
// 2^0 * 5^1 = 5
// 2^3 * 5^0 = 8
@earlonrails
earlonrails / .bash_profile
Created January 29, 2016 21:33
Manage two github accounts by using the user.email to toggle which ssh key to use
#!/usr/bin/env bash
export GIT_SSH='dynamic_git_command.sh'
swapgitmail() {
local email=$(git config --global user.email)
if [ "$email" = "[email protected]" ];then
git config --global user.email "[email protected]"
echo "$(git config --global user.email)"
else
@earlonrails
earlonrails / docker-command.sh
Last active December 2, 2019 18:27
docker commands
docker rmi $(docker images -a | grep "^<none>" | awk '{print $3}')
docker images -q --filter "dangling=true" | xargs docker rmi
docker rmi $(docker images -q --filter "dangling=true")
docker rmi $(docker images -a | grep "^<none>" | awk "{print $3}")
docker ps -q -a | xargs docker rm
@earlonrails
earlonrails / mockNeoism.go
Last active March 9, 2022 09:45
Mock neo4j/neoism connection in go for testing
package testhelpers
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"github.com/jmcvetta/neoism"
)
@earlonrails
earlonrails / email_regex.rb
Last active August 29, 2015 14:25
Email regex ruby
/^[\w\-\.]+\@[\w\.\-]+\.\w{2,4}$/
# matches
# [email protected]
# [email protected]
# [email protected]
# [email protected]
# [email protected]
@earlonrails
earlonrails / common_char.rb
Created July 21, 2015 20:17
two character string arguments and returns # a string containing only the characters found in both strings. A version which is order N-squared and one which is order N, in RUBY!
# Write a function f(a, b) which takes two character string arguments and returns
# a string containing only the characters found in both strings in the order of a.
# Write a version which is order N-squared and one which is order N.
string_a = "abcdefg"
string_b = "afcbedf"
def common_char_n_squared(string1, string2)
common_chars = ""
string1.each_char do |i|