Skip to content

Instantly share code, notes, and snippets.

@itsanna
itsanna / main.go
Created January 27, 2018 00:03
architectureGraphDataGenerator
package main
import (
"bufio"
"encoding/csv"
"fmt"
"io"
"os"
"strings"
"log"
@itsanna
itsanna / protein_synthesis.go
Last active May 29, 2017 03:08
Interview Question: Implement protein synthesis
package main
import (
"fmt"
"strings"
)
/*
Implement: Protein synthesis
@itsanna
itsanna / spiral_order.go
Created March 21, 2017 01:19
Print 2-D array in spiral order in Golang
package main
import "fmt"
/*
Print 2-D array in spiral order
numbers := [
[2, 4, 6, 8],
@itsanna
itsanna / github.js
Created June 2, 2016 20:39
Reducer that takes in previous `github` state and returns the new `github` state
const initialState = {
user: {}
}
export default function github(state = initialState, action) {
switch (action.type) {
case 'REQUEST_USER':
return { ...state, isFetchingUser: true }
case 'RECEIVE_USER': {
return {
import 'whatwg-fetch'
const GITHUB_API = 'https://api.github.com'
function receiveUser (name, json) {
return {
type: 'RECEIVE_USER',
user: json
}
}
@itsanna
itsanna / SearchBar.js
Last active June 2, 2016 20:36
<SearchBar /> a React.js component
import React, { Component } from 'react'
class SearchBar extends Component {
constructor (props) {
super(props)
this.state = {
username: ''
}
}
/*
Given a page of text, output the characters ordered from highest to lowest occurrence.
for example, the output for 'banana!' is
a: 3
n: 2
b: 1
!: 1
@itsanna
itsanna / getElementsByTagName.js
Created February 28, 2016 07:56
reimplement getElementsByTagName
/*
List of elements of type/ reimplement getElementsByTagName
* Returns a list of all elements of given type which are children of provided parent.
* @param {! string} `tagName` The tag name of the element. eg. 'DIV'
* @param {Node} `parent` The root node under which the search must be performed.
* @return {!Array} A list of elements of given type that are children of provided parent. Empty if none could be found.
*/
@itsanna
itsanna / reducer-test.js
Created January 12, 2016 07:01
Testing jobs reducer
import test from 'tape'
import jobsReducer from '../src/client/reducers/jobs'
const actualReducer = jobsReducer
const initialState = {
list: []
}
const initialState2 = {
list: [ { title: 'Actress' } ]
}
@itsanna
itsanna / numberGuessingGame.js
Last active December 1, 2015 21:43
Number guessing game
// Write a function that is a number guessing game. It should determine a random number from 1-100, and let the user guess the number.
// It should report back whether their guess is correct, too high, or too low. Important: if the user guesses a number they've already
// guessed, it should tell them they have previously guessed this number. Until they guess the correct number, it should continue to prompt
// them. Once they've guessed the correct number, it should congratulate them and tell them how many guesses they took to solve the problem
// (minus any duplicate guesses).
function game() {
var guess = [] // store user's guesses
var randNum = Math.floor(Math.random() * (100)) + 1
function numberGuesser(num) {