Skip to content

Instantly share code, notes, and snippets.

View nullset2's full-sized avatar

Alfredo Gallegos nullset2

View GitHub Profile
@nullset2
nullset2 / The Technical Interview Cheat Sheet.md
Last active August 25, 2015 20:02 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@nullset2
nullset2 / hashstuff.rb
Last active November 8, 2015 00:47
Summing values from Bidimensional hash
#see http://nullset2.tumblr.com/post/132761268939/a-quick-recipe-with-hashes
data = { :A => { :D => 100, :E => 200, :F => 300}, :B => { :G => 10, :H => 20, :I => 30 }, :C => { :J => 1, :K => 2, :L => 3 } }
# => {:A=>{:D=>100, :E=>200, :F=>300}, :B=>{:G=>10, :H=>20, :I=>30}, :C=>{:J=>1, :K=>2, :L=>3}}
# data = Hash.new { |k, v| k[v] = Hash.new { |kk, vv| kk[vv] = 0 } } # or you could also initialize that shit like this, then assign stuff to each key-value pair individually
vals = data.map do |k, v| # saving the sums elsewhere temporarily
v.values.reduce(&:+) #sum the corresponding values to ALL the elements in the "second dimension" of this hash, per first dimension key
end
# => [600, 60, 6]
#give me a CSV file with 1,800,000 random dates from february 01 2013 to february 28 2013 in a single column
require 'date'
File.open("juliodata.csv", "w") do |f|
1800000.times do
f << "#{Date.new(2013, 02, rand(1..28))}\n"
end
end
#prime number calculator
#alfredo gallegos, 2015
def is_prime(j)
case j
when j <= 0, 1
return false
else # j > 3
( 2..Math::sqrt(j).floor ).each do |k| # any divisors in range from 2 to j
import re
while True:
input_str = raw_input("What's your name? ") #reads user input
if ( re.match('[0-9]+', input_str) ): # while the input doesn't match the pattern "one or more numbers in the string"
print "Your name must NOT include numbers." #error out of the program
else:
break
print "if you see this, the entered name fullfilled the logical condition"
~/config $ cat database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: mysql2
pool: 5
import groovyx.net.http.*
//if you import these classes statically, you'll be able to use the classes you import with this without qualified access
//notice how we're using just POST in some calls below, for example, instead of having to do Method.POST
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
class LoginService{
def authenticateURL = //url
def decryptURL = //url
def merge(a, b):
i = 0
j = 0
c = []
while(i < len(a) and j < len(b)):
if(a[i] <= b[j]):
c.append(a[i])
i += 1
else:
@nullset2
nullset2 / dabblet.css
Last active September 15, 2016 19:39 — forked from chriscoyier/dabblet.css
Untitled
span {
display: none;
}
#toggle-1:checked ~ [class=appendDataCheckbox]{
display: inline;
}
@nullset2
nullset2 / dabblet.css
Last active September 15, 2016 21:16
Untitled
span {
display: none;
}
[value="pdf"]:checked ~ [class=appendDataCheckbox]{
display: inline;
}