This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import HttpResponse | |
from django.views import generic | |
import json | |
class JSONView(generic.View): | |
callback_parameter = 'callback' | |
def get_json_data(self, request, *args, **kwargs): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git config --global branch.autosetuprebase always | |
git config --global pull.rebase preserve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DimensionsValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
# I'm not sure about this: | |
dimensions = Paperclip::Geometry.from_file(value.queued_for_write[:original].path) | |
# But this is what you need to know: | |
width = options[:width] | |
height = options[:height] | |
record.errors[attribute] << "Width must be #{width}px" unless dimensions.width == width | |
record.errors[attribute] << "Height must be #{height}px" unless dimensions.height == height |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Integer | |
def palindrome? | |
return self.to_s == self.to_s.reverse | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"bufio" | |
"fmt" | |
"strings" | |
) | |
type Stack struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | |
Very basic single-file binary file uploading via Elm port. | |
One area for improvement is in error handling. Since I only care if a file | |
uploads successfully, that's all I'm passing in the callback port. | |
One known issue is since we execute the port on "change", uploading | |
the same file multiple times in a row will not have any affect since | |
the DOM element doesn't "change" if the same file gets selected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reindex(self, entities): | |
# Note - for some period of time, this doubles the memory usage of your ES cluster | |
# If this is a problem, the ES reindex function can take source/destination cluster so you can | |
# throw away the entire old cluster after everything is migrated. | |
# This assumes you use an alias (shown as `self.index` in this example) for your API calls | |
# 1. Create a new index with a unique name | |
# Set all of the index settings on the new index | |
# Set all of the doctype mappings on it | |
# 2. Use the Elasticsearch reindex helper to copy all documents over to new index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digits = inp | |
|> String.codepoints() | |
|> (fn [hd | tl] -> [hd | tl] ++ [hd] end).() | |
|> Enum.map(&String.to_integer/1) | |
|> Enum.chunk_every(2, 1, :discard) | |
|> Enum.filter(fn [a, b] -> a == b end) | |
|> Enum.map(&List.first/1) | |
|> Enum.sum | |
|> IO.inspect() |