Skip to content

Instantly share code, notes, and snippets.

View pnispel's full-sized avatar

Paul Nispel pnispel

View GitHub Profile
@pnispel
pnispel / insertion_sort.cpp
Created September 3, 2014 01:08
insertion sort
int * sort (int arr [], int len) {
for (int i = 1; i < len; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
@pnispel
pnispel / fast.rs
Last active October 1, 2015 04:46
bad rust?
let start = time::now();
let metadata = try!(fs::metadata(&path));
let mut file = try!(File::open(&path));
let mut buf = vec![0u8; metadata.len() as usize];
try!(file.read(&mut buf));
buf.make_ascii_lowercase();
let mut str: &str = try!(str::from_utf8(&buf));
export default ({nestedPhoto}) => {
return (
<PhotoCard
dispatch={(action) => nestedPhoto(action, {id: blah})}
/>
<Viewer
/* ???? needs to dispatch some to nestedPhoto and some to the parent of nestedPhoto */
/>
);
}
@pnispel
pnispel / example.js
Created September 7, 2017 17:41
react without es6 or jsx
function UploadFileToken(props) {
var ce = React.createElement;
var file = props.file;
return ce('div',
{
className: 'procore-upload-file-token',
key: file.uuid,
},
ce('span', {
@pnispel
pnispel / App.jsx
Created September 21, 2017 20:30
Dropdowns after init
import JQueryTypeDropdown from './JQueryTypeDropdown.jsx'
import FoundationTypeDropdown from './FoundationTypeDropdown.jsx'
const App = () => {
return (
<div>
<JQueryTypeDropdown />
<FoundationTypeDropdown />
</div>
);
@pnispel
pnispel / prostore_file.rb
Created October 4, 2017 18:38
Class method include module
class ProstoreFile < ActiveRecord::Base
...
include ProstoreFile::UrlHelpers
...
end
def self.find_optimal_batch_size
times = []
[100, 1_000, 10_000, 100_000].each do |batch_size|
times << [timed_query(batch_size), batch_size]
end
times.sort
end
@pnispel
pnispel / clear_cached_drawing_revisions_zip_url.rb
Created October 20, 2017 17:59
Make DrawingRevision.zip_url nil for company
class ClearCachedDrawingRevisionZipUrl
def self.clear_drawing_revision_zip_urls_for_companies(company_ids)
Company.where(id: company_ids).each do |company|
DrawingRevision.
joins("JOIN drawing_areas ON drawing_areas.id = drawing_revisions.drawing_area_id").
joins("JOIN projects ON projects.id = drawing_areas.project_id").
joins("JOIN companies ON companies.id = projects.company_id").
update_all(zip_url: nil)
end
end
@pnispel
pnispel / rebuild_drawing_revision_zip_urls.rb
Last active October 23, 2017 21:09
Rebuild DrawingRevision.zip_url for company
class RebuildDrawingRevisionZipUrls
def self.rebuild_drawing_revision_zip_urls_for_companies(company_ids)
Company.where(id: company_ids, use_govcloud: true).each do |company|
DrawingRevision.joins(drawing_area: {project: :company}).
where("drawing_revisions.zip_url IS NOT NULL AND companies.id = ?", company.id).
find_each do | drawing_revision |
zip_url = build_url(drawing_revision.s3_zip_key, drawing_revision.zip_profile)
drawing_revision.update_column('zip_url', zip_url) if zip_url
end
@pnispel
pnispel / worker.rb
Last active October 26, 2017 20:20
pft
module StorageProfileKey
# This class backfills storage_profile_key on prostore_file_thumbnails.
# Once the backfill completes and there is a not null constraint
# and default value on the column, this class can be removed.
class ProstoreFileThumbnailsBackfillWorker
include Sidekiq::Worker
sidekiq_options queue: :data_migration
def self.enqueue_prostore_file_thumbnails(starting_id:, ending_id:)