Skip to content

Instantly share code, notes, and snippets.

View scarfacedeb's full-sized avatar
👀

Andrew Volozhanin scarfacedeb

👀
View GitHub Profile
@scarfacedeb
scarfacedeb / result_stream.ex
Created January 18, 2018 23:52
Possible refactoring of ExTwillio.ResultStream
defmodule ExTwilio.ResultStream do
@moduledoc """
Generate a stream of results for a given Twilio API URL. Pages are lazily
loaded on demand.
## Example
ExTwilio.ResultStream.new(ExTwilio.Call)
|> Stream.map(fn call -> call.sid end)
|> Enum.take(5)
@scarfacedeb
scarfacedeb / nginxrewrite2.md
Created August 15, 2016 13:12 — forked from esfand/nginxrewrite2.md
Nginx Rewrite
@scarfacedeb
scarfacedeb / define.py
Last active March 12, 2016 15:44
Import from kindle vocabulary to anki
#!/usr/bin/env python
"""
Modified from
http://macscripter.net/viewtopic.php?id=26675
http://apple.stackexchange.com/questions/90040/look-up-a-word-in-dictionary-app-in-terminal
HowTo
@scarfacedeb
scarfacedeb / Gruntfile.js
Created November 9, 2015 12:05
Grunt task to compile svg
// To optimize, minify and combine svg files
//
// Example:
// grunt --target="../app/views/public/shared/_svg.html"
// grunt --target="../app/views/public/shared/_categories_svg.html" --source="categories/*.svg"
//
module.exports = function(grunt) {
// process argv
var target = grunt.option('target') || '../app/views/public/shared/_svg.html';
@scarfacedeb
scarfacedeb / nginx.conf
Last active August 29, 2015 14:28 — forked from conorh/nginx.conf
Using Nginx as a caching proxy for Refile with Ruby on Rails
http {
...
proxy_cache_path /data/perch.squaremill.com/shared/image_cache levels=1:2 keys_zone=images:10m;
...
}
@scarfacedeb
scarfacedeb / find_missing_indices.rb
Created May 13, 2015 14:44
Simple script to find missing unique constrains for uniqueness validations in rails
# run from the root: ruby find_missing_indices.rb
require File.expand_path("../config/environment", __FILE__)
Rails.application.eager_load!
models = ActiveRecord::Base.descendants
conn = ActiveRecord::Base.connection
missing_index = []
models.each do |model|
@scarfacedeb
scarfacedeb / check_validation_details.rb
Created May 13, 2015 11:13
Helper method to check validation errors
# required: Rails 5 or active_model-errors_details gem
# see: https://cowbell-labs.com/2015-01-22-active-model-errors-details.html
module CheckValidationDetails
# Check if the given error exists on given attribute
#
# @param attribute [Symbol] model attribute
# @param error [Symbol] machine-friendly error name
# @return [Boolean] whether or not any given error exists
def error?(attribute, error)
errors.details.key?(attribute) && errors.details[attribute].any? { |err| err[:error] == error }
#!/bin/sh
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
@scarfacedeb
scarfacedeb / importer.rb
Created February 11, 2015 19:27
Trick to make activerecord-import work with refile
brands = []
brand = Brand.new
brand.name = "Harry's"
brand.remote_logo_url = "http://example.com/image.png" # store file in cache and give it an ID
brand.logo_attacher.store! # force refile to fill logo_id attribute without .save
brands << brand
# Bulk import all of the brands at once. NO CALLBACKS!