Skip to content

Instantly share code, notes, and snippets.

View billmei's full-sized avatar
☑️
Verified Profile

Bill Mei billmei

☑️
Verified Profile
View GitHub Profile
@billmei
billmei / interest_rate_alert.py
Created March 6, 2017 05:22
Send yourself an email if the Federal Reserve interest rate rises above a trigger value
#!/usr/bin/env python
"""
Monitor the Federal Reserve Interest rates and email
an alert if the risk-free rate exceeds a certain percentage
"""
from bs4 import BeautifulSoup
import requests
import os
# This is a percent value
@billmei
billmei / joins.sql
Last active July 7, 2016 18:35
Joins in SQL
CREATE TABLE author(author_id integer PRIMARY KEY, name text, age integer);
INSERT INTO author VALUES(1, "Alice", 25);
INSERT INTO author VALUES(2, "Bob", 32);
INSERT INTO author VALUES(3, "Charlie", 29);
CREATE TABLE posts(id integer PRIMARY KEY, author_id integer, post_name text);
INSERT INTO posts VALUES(1, 1, "foo");
INSERT INTO posts VALUES(2, 1, "bar");
INSERT INTO posts VALUES(3, 1, "baz");
INSERT INTO posts VALUES(4, 2, "quz");
@billmei
billmei / palette.scss
Created May 15, 2015 16:27
Color palettes
/* Coolors Exported Palette - coolors.co/1be7ff-6eeb83-e4ff1a-e8aa14-ff5714 */
$color1: #1be7ff;
$color2: #6eeb83;
$color3: #e4ff1a;
$color4: #e8aa14;
$color5: #ff5714;
/* Coolors Exported Palette - coolors.co/247ba0-70c1b3-b2dbbf-f3ffbd-ff1654 */
@billmei
billmei / shuffle.js
Created April 20, 2015 15:39
Shuffle algorithm for JavaScript
// Randomly shuffles an array in-place using Fisher-Yates algorithm
// http://stackoverflow.com/a/12646864
Array.prototype.shuffle = function() {
for (var i = this.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = this[i];
this[i] = this[j];
this[j] = temp;
}
return this;
@billmei
billmei / alertModal.js
Created April 8, 2015 19:00
Display error messages to the user using a Bootstrap modal
function alertModal(title, body) {
// Display error message to the user in a modal
$('#alert-modal-title').html(title);
$('#alert-modal-body').html(body);
$('#alert-modal').modal('show');
}
@billmei
billmei / index.html
Created April 6, 2015 17:16
Responsive Tables in pure CSS
<table>
<thead>
<tr>
<th>Payment</th>
<th>Issue Date</th>
<th>Amount</th>
<th>Period</th>
</tr>
</thead>
<tbody>
@billmei
billmei / prototypes.js
Created March 30, 2015 18:30
Lesson plan for teaching JavaScript prototypes
// Floobits:
// https://floobits.com/Kortaggio/prototypes
// Inheritance Diagram:
// https://docs.google.com/drawings/d/1PTgRq2UPD0LilvZOFIpTWUsgzGo1iN7XdL7X6BXvA-U/edit?usp=sharing
// Hi guys! Today I'm going to tell you about prototypes in JavaScript.
// Before I get started, I want to ask you a question:
// How many of you have:
// - started a business?
# Interview Cake question #33
# I have an array where every number in the range 1..n appears once except
# for one number which appears twice. Write a function for finding the number
# that appears twice.
from __future__ import print_function
# Since the list is already sorted, we can binary search for the repeated
# number. This runs with O(log n) additional time and O(1) additional space.
def which_appears_twice(the_list):
lower_bound = 0
# Interview Cake question #30
# Write an efficient function that checks whether any permutation of an input
# string is a palindrome.
from __future__ import print_function
# Strategy: XOR every character with each other. Runtime is O(n).
def is_palindrome(message):
# Hash all the chars to prevent the result from colliding with
# the ascii value of a different, but valid character when xoring.
hashed_chars = map(hash, list(message))