Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

# ---- Build Stage ----
# The version of Alpine to use for the final image
# This should match the version of Alpine that the builder image uses
ARG ALPINE_VERSION=3.10
FROM elixir:1.9.4-alpine AS builder
# The following are build arguments used to change variable parts of the image.
# The name of your application/release (required)
@Nitrino
Nitrino / totp_2fa.rb
Created May 17, 2018 16:49
Rails mixin module for Two Factor Authentication (TOTP)
module OneTimePassword
# Concern containing logic and methods for OTP authentication.
# Is used Time-based One-time Password Algorithm(TOTP)
# https://tools.ietf.org/html/rfc6238
extend ActiveSupport::Concern
OTP_DIGITS = 6
OTP_NUMBER_OF_BACKUP_CODES = 10
OTP_BACKUP_CODE_LENGTH = 12
class SharePhoto
attr_reader :image
SRC_PATH = Rails.root.join("app/assets/images/private_share/")
def self.update_all
source_files = SRC_PATH.join("src/backgrounds")
Dir.foreach(source_files).each do |image_name|

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@Nitrino
Nitrino / helpful_library.md
Created March 30, 2014 07:47
Полезные библиотеки для фронт-энда

Карусели:

  1. https://github.com/kenwheeler/slick/ - удобный компонент для создания разныХ каруселей

CSS фреймворки:

  1. http://thoughtbot.github.io/refills/ - это «расфасованные» паттерны, копоненты, миксины и все самое лучшее из Bourbon, Bitters и Neat.
  2. http://getwebplate.com/ - очередной «easy and awesome» CSS фреймворк, который, возможно, кому нибудь пригодиться

Утилиты:

  1. https://incident57.com/codekit/index.html
  2. http://alphapixels.com/prepros/
@Nitrino
Nitrino / partial.md
Last active August 29, 2015 13:56
How Much Time Does Rendering a Partial Really Take? | Author: Justin Weiss http://www.justinweiss.com/

How Much Time Does Rendering a Partial Really Take?

I’ve heard from some people that are worried about breaking apart large Rails views into smaller partials: How much time does rendering a partial really take? Will the performance impact of calling the partials outweigh the benefits in code readability?

I ran some numbers to give an example on how simple partial rendering compares to inline rendering, so we can discuss the tradeoff later. This is the code I used to benchmark, in a brand new Rails app (with config.cache_classes = true):

app/views/test/show.html.erb

<% require 'benchmark'
   Benchmark.bmbm do |x|
mkdir -p ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript
curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Syntaxes/CoffeeScript.tmLanguage
curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Preferences/CoffeeScript.tmPreferences
@Nitrino
Nitrino / application_helper.rb
Last active December 20, 2015 12:09
qr-code helper generator
def qr_code(size, url)
"https://chart.googleapis.com/chart?cht=qr&chs=#{size}x#{size}&chl=#{CGI.escape(url)}"
end
@Nitrino
Nitrino / gems.md
Last active December 18, 2015 21:09
Список используемых гемов

Список используемых гемов:

  1. active_admin - создание админки
  2. better_errors - заменяет стандартные ошибки Rails
  3. bullet - помогает отследить моменты где происходит N+1 запросов и нужно использовать eager loading
  4. cancan - гем для авторизации и прав пользователя
  5. the role - авторизации для 4х рельс, мне нарвится больше чем cancan
  6. client_side_validations - автоматически создаёт JavaScript валидацию на клиенте из существующих серверных валидаций. Очень классная штука. скринкаст: http://railscasts.com/episodes/263-client-side-validations
  7. devise - аутентификация пользователей.
  8. factory_girl - создание фабрик, замена стандартным fixtures
@Nitrino
Nitrino / emoji.md
Last active December 18, 2015 10:09
ios emoji in rails + mysql

Emoji in Rails + MySQL

UTF8 содержит три байта на символ, что не в полной мере отражает такие языки как японский. В ios используются смайлы emoji тоже пришедшие из японии и старая версия utf8 использующая 3 байта на символ их не поддерживает. Новая версия utf8 (utf8mb4) использует 4 байта на символ и в полной мере поддерживает все языки и спецсимволы. MySQL c версии 5.5.3 поддерживает utf8mb4

Для поддержки emoji нужно конвертировать нужную таблицу или всё базу в utf8mb4. Сделать это можно с помощью команд: Для базы: