Skip to content

Instantly share code, notes, and snippets.

John Cipriano johncip

Block or report user

Report or block johncip

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@johncip
johncip / 264.java
Last active Feb 17, 2016
Count on Cantor
View 264.java
/*
* 264 - Count on Cantor
*
* Given an input value N, print the Nth term in Cantor's enumeration.
*
* There may be a simpler closed form of this. However, what strikes me as
* possible right now is: we figure out what diagonal n is on, which gives us
* the beginning of that diagonal (1/2, 3/1, 1/4, 5/1, etc.). Then, we adjust
* the numerator and denominator based on the distance from the first term in
* the diagonal and the direction it takes (up-right for odd, down-left for
@johncip
johncip / uva-fast-io
Created May 25, 2014
Contest problem fast I/O template
View uva-fast-io
/*
* Title
*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
View name-length-histogram.txt
User name metrics
Bin width: 1
Each # represents 500 users.
LENGTH OF FIRST NAME
====================
bins: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]
freqs: [36, 510, 2547, 5905, 10086, 11103, 9461, 5363, 3918, 2780, 3515, 3655, 3609, 3213, 2246, 1469, 968, 576, 410, 253, 189, 162, 102, 57, 51, 42, 31, 24, 15, 4, 1, 4, 2, 2, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1]
01:
02: #
@johncip
johncip / print_fixtures.rb
Last active Feb 17, 2016
Print fixtures used
View print_fixtures.rb
log = StringIO.new
ActiveRecord::Base.logger = Logger.new(log)
Gradescope::Application.config.colorize_logging = false
RSpec.configure do |config|
config.after :suite do
lines = log.tap(&:rewind).readlines.to_a
matching = lines.map do |line|
next unless line =~ /Load/
View viewer_components.opml
<?xml version="1.0"?>
<opml version="2.0">
<head>
<ownerEmail>johnmikecip@gmail.com</ownerEmail>
</head>
<body>
<outline text="div#assignment-submission-app" >
<outline text="(modals)" />
<outline text="&lt;b&gt;AssignmentSubmissionViewer&lt;/b&gt;" _note="&lt;b&gt;div#assignment-submission-show&lt;/b&gt;" >
<outline text="PageViewerContainer" _note="div#assignment-submission-viewer&#10;(merge with child if possible)" >
@johncip
johncip / table_with_fixed_header.sass
Last active Apr 21, 2016
Pure-CSS fixed table headers
View table_with_fixed_header.sass
table.fixed-header
table-layout: fixed
border-collapse: collapse
thead tr
display: block
position: relative
tbody
display: block
overflow: auto
width: 100%
@johncip
johncip / browserify_react_lib.sh
Last active Apr 22, 2016
Browserify 3rd-party React components found on npm
View browserify_react_lib.sh
# Browserify 3rd-party React components found on npm
# (prevents React & ReactDOM from being bundled)
export PACKAGE='simple-react-modal' # npm package
export EXPORT_NAME='SimpleReactModal' # will end up on window with this name
mkdir project && cd project
npm init -f
npm install -D browserify react react-dom
@johncip
johncip / install_guest_additions.sh
Last active May 26, 2016
Install VirtualBox Guest Additions on Ubuntu
View install_guest_additions.sh
# Install VirtualBox guest additions on Ubuntu
# https://www.vagrantup.com/docs/virtualbox/boxes.html
VB_VERSION='5.0.20'
wget "http://download.virtualbox.org/virtualbox/$VB_VERSION/VBoxGuestAdditions_$VB_VERSION.iso"
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro "VBoxGuestAdditions_$VB_VERSION.iso" /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
rm "VBoxGuestAdditions_$VB_VERSION.iso"
@johncip
johncip / rails_eager_load.md
Last active Jun 22, 2019
Active Record eager loading strategies
View rails_eager_load.md

N+1 query problem

  • ORMs make it easy to a query per loop iteration, which we want to avoid

eager_load

  • single query (left outer join)
  • can reference the other table's columns in where

preload

  • a few queries (one per table)
  • typically faster
View pronto_hack.rb
❯ vi /usr/local/lib/ruby/gems/2.3.0/gems/pronto-0.8.2/lib/pronto/formatter/text_formatter.rb
# change line 17 to ...
# "[#{message.runner.title}] #{format_location(message)} #{format_level(message)}: #{message.msg}".strip
❯ pronto run -r reek
Running Pronto::Reek
[reek] app/decorators/course_membership_decorator.rb:21 I: Is controlled by argument 'current_user' (ControlParameter)
You can’t perform that action at this time.