Skip to content

Instantly share code, notes, and snippets.

View JKring's full-sized avatar

jake kring JKring

View GitHub Profile
@JKring
JKring / colors.js
Created December 18, 2013 01:58
colors!!
var colorUtils = {
existingColors: {},
red: [5.5, 0.765, 0.80],
convertHSVtoRGB: function(h, s, v) {
var r, g, b, i, f, p, q, t;
h = h / 360;
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
@JKring
JKring / schema.xml
Created December 12, 2013 22:50
Schema for Solr4 and Sunspot
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@JKring
JKring / controller.rb
Created October 5, 2013 20:48
async photo uploading
def upload_photo
event = Event.find(params[:event_id])
params.delete(:event_id)
icon = EventIcon.create(params)
# This requires setting up a many-to-one relationship between icons and events
event.icons << icon
event.save!
render json: {
id: icon.id,
name: icon.photo_file_name,
@JKring
JKring / form.html
Last active December 24, 2015 18:49
async photo uploading
<script type="text/javascript">
// You'll probably have to call this from $(document).ready because it requires the DOM to be loaded.
function bindToForm(){
$("#upload-photo-form").fileupload({
dataType: 'json',
progress: function() {
// Indicate that the upload has begun
},
done: function(e, data) {
// use data.id, data.name, and data.url to display the photo
@JKring
JKring / save.rb
Created August 16, 2013 21:36
writer save time
Writer.where().each do |w|
start_time = Time.now
w.save!
puts w.id if (Time.now - start_time) > 3
end
@JKring
JKring / gist:6116618
Created July 30, 2013 20:29
migrating team ids
id_map = {
"soon-to-be-deleted-team-id" => "replacement-team-id",
"other-soon-to-be-deleted-team-id" => "other-replacement-team-id"
}
id_map.each_pair do |old_id, new_id|
old_id = BSON::ObjectId(old_id)
new_id = BSON::ObjectId(new_id)
classes = [BlogPost, Business, Job, FinishedJob, PitchSet, TempJob]
classes.each do |cl|
@JKring
JKring / payday.rb
Created June 27, 2013 23:02
payday logic
def is_payday?(t)
return true if (t.end_of_month.saturday? || t.end_of_month.sunday?) && t.friday?
return true if [13, 14].include?(t.day) && t.friday?
return true if (t.end_of_month == t.midnight || t.day == 15) && !(t.saturday? || t.sunday?)
return false
end
@time = DateTime.now
100.times do |i|
t = @time.advance(days: i)
## On BuyerEmailer
# Now we don't have to call it in every method...
sendgrid_category 'buyer'
# This is the hash that connects preference levels to emails
@@preference_levels = {
claimed: "important"
}
@JKring
JKring / revs.rb
Created May 31, 2013 22:12
document.revs
[
["Initial Draft", "First draft of first piece of content==========abc123==========First draft of second piece of content"],
["Second Draft", "Second draft of first piece of content==========abc123==========Second draft of second piece of content"],
["Final Draft", "Final draft of first piece of content==========abc123==========Final draft of second piece of content"]
]
@JKring
JKring / too_long.rb
Created May 30, 2013 02:32
long query
query = {:per_page=>15, :page=>1, :blacklisted=>false, :not_team_ids=>["5090770bd6841267b10004b4"], :search_terms=>nil, :sort=>[:team_scores_5090770bd6841267b10004b4_num_overall, :desc]}
solrquery = Writer.search do
all_of do
without(:removed).equal_to(true)
without(:blacklisted).equal_to(true) if query[:blacklisted] == false
with(:has_photo).equal_to(true) if query[:has_photo]
with(:team_ids).any_of(query[:team_ids]) if query[:team_ids]
without(:team_ids).any_of(query[:not_team_ids]) if query[:not_team_ids]
with(:group_ids).any_of([query[:group_ids]]) if query[:group_ids]
end