Skip to content

Instantly share code, notes, and snippets.

View brockthebear's full-sized avatar
💭
Ship Ship Ship

Brock Boren brockthebear

💭
Ship Ship Ship
View GitHub Profile
#!/bin/python3
import re
n = int(input().strip())
s = "{0:b}".format(n)
out = max(len(a) for a in re.findall(r'1+', s))
print(out)
@brockthebear
brockthebear / csv_import.py
Created May 18, 2017 16:43
Import CSV file to MySQL database
#!/usr/bin/env python3
"""
Essentially just a python script to run the sql command below.
mysqlimport --ignore-lines=1 --fields-terminated-by=, --columns=csv_headers --local -u root -p db_name file.csv
"""
using System;
public class HelloWorld
{
private const string Greetings = "Hello, World!";
public string Hello()
{
return Greetings;
}
#!/usr/bin/env bash
set -o errexit
set -o nounset
main() {
echo "Hello, World!"
}
main
using System;
public static class Leap
{
public static bool IsLeapYear(int year)
{
bool multipleOf4 = YearIsDivisibleByFactor(year, 4);
bool multipleOf100 = YearIsDivisibleByFactor(year, 100);
bool multipleOf400 = YearIsDivisibleByFactor(year, 400);
@brockthebear
brockthebear / mongo-export-csv.js
Last active May 16, 2019 17:36
Export a MongoDB collection and write to a CSV. Uses json2csv, async/await, and dotenv.
require('dotenv').config();
const { AsyncParser } = require('json2csv');
const fs = require('fs');
const MongoClient = require('mongodb').MongoClient;
const url = `mongodb://localhost:27017`;
const HEADERS = ['first_name', 'last_name', 'middle_name', 'id'];
const FIELDS = ['name.first_name', 'name.last_name', 'name.middle_name', 'id'];
@brockthebear
brockthebear / csv_concat.py
Created May 18, 2017 16:44
Combine multiple CSVs into one.
import glob
files = glob.glob("*.csv")
header_saved = False
with open('output.csv', 'w') as fout:
for file in files:
with open(file) as fin:
header = next(fin)
if not header_saved:
@brockthebear
brockthebear / fabfile.py
Last active June 7, 2019 17:14
Example deployment of a Node app using Fabric
#!/usr/local/bin/python3
# List tasks with fab2 -l
import os
import os.path as path
from fabric2 import Config, Connection, task
import patchwork.transfers as transfer
# Define values in .env file.
@brockthebear
brockthebear / web-dev-resources.md
Created July 29, 2019 16:50
Resources for anybody wanting to learn how to code (with an emphasis on front-end tech).

Web Dev Resources

⭐ = favorite


Required Reading

Paul Ford: What Is Code? - It’s long but nothing ever got me so excited about learning to code as much as this.

Tutorials

  • Free (mostly)