Skip to content

Instantly share code, notes, and snippets.

View danielrobertson's full-sized avatar
☁️
Working on Cloudflare dashboard experiences

Daniel danielrobertson

☁️
Working on Cloudflare dashboard experiences
View GitHub Profile
@danielrobertson
danielrobertson / range.py
Last active August 29, 2015 13:56
My idea of what Python 3's range(begin, end, step) looks like
def range(begin, end = None, step = 1):
if step == 0:
raise Exception("Step size cannot be 0")
if end == None:
end, begin = begin, 0
while (abs(begin + step - end)) <= (abs(begin - end)):
yield begin
begin += step
assert(list(range(10)) == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
@danielrobertson
danielrobertson / quizzes.c++
Created February 27, 2014 03:40
Quizzes CS 371p
/* -----------------------------------------------------------------------
1. Show the cycle for 3.
What is the cycle length?
[Collatz]
(2 pts)
3, 10, 5, 16, 8, 4, 2, 1
8
*/
@danielrobertson
danielrobertson / stddev.py
Created February 27, 2014 05:37
Standard deviation
import math
def stddev(numbers):
n = len(numbers)
mean = sum(numbers) / n
dev = [x - mean for x in numbers]
dev2 = [x * x for x in dev]
return math.sqrt(sum(dev2) / n)
def z_score(n, l):
mean = sum(l) / len(l)
return (n - mean) / (stddev(l) / math.sqrt(len(l)))
@danielrobertson
danielrobertson / intellij.desktop
Last active August 29, 2015 14:01
How to add an icon for IntelliJ. Update the Icon and Exec to where you unzipped idea-IC-135.690.gz and installed IntelliJ.
// create file:
sudo vim /usr/share/applications/intellij.desktop
// add the following
[Desktop Entry]
Version=13.0
Type=Application
Terminal=false
Icon[en_US]=/home/daniel/idea-IC-135.690/bin/idea.png
Name[en_US]=IntelliJ
@danielrobertson
danielrobertson / JDBCService
Last active August 29, 2015 14:08
Connect to MySQL with JDBC
// load the MySQL driver. Alternatively, use the Maven http://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.33
Class.forName("com.mysql.jdbc.Driver");
// connect to database named openstack_projects on port 3306
String url = "jdbc:mysql://localhost:3306/openstack_projects";
Connection conn = DriverManager.getConnection(url, "root", "");
// make a query
String sql = "select * from projects";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
@danielrobertson
danielrobertson / examplePayload
Created November 12, 2014 00:01
Field Day registration
{
"registration": {
"children": [
{
"firstName": "joe",
"lastName": "bro",
"dob": "11 march 1990"
},
{
"firstName": "jay",
@danielrobertson
danielrobertson / RemoveDuplicates.py
Created March 19, 2015 17:48
Remove duplicates in CSV
import pandas as pd
toclean = pd.read_csv('fileWithDuplicates.csv')
deduped = toclean.drop_duplicates('columnName')
deduped.to_csv('fileWithoutDuplicates.csv')
@danielrobertson
danielrobertson / .gitconfig
Last active June 12, 2021 22:26
.gitconfig
[user]
name = Daniel Robertson
email = danielrobertson733@gmail.com
[alias]
p = pull
a = add
st = status
ci = commit
br = branch
class Multiton {
static HashMap<String, Multiton> map = new HashMap<String, Multiton>();
private Multiton(String key) { ... }
static Multiton newMultion(String key) {
result = map.get(key);
if(result == null) {
result = new Multiton(key);
map.add(key, result);