Skip to content

Instantly share code, notes, and snippets.

class Users::SessionsController < Devise::SessionsController
# Have to reimplement :recall => "failure"
# for warden to redirect to some action that will return what I want
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "failure")
# set_flash_message :notice, :signed_in
sign_in_and_redirect(resource_name, resource)
end
@sjava
sjava / gist:1457742
Created December 11, 2011 02:14 — forked from scott-stewart/gist:1269328
SimpleForm Nested Label Component for Twitter Bootstrap CSS
# <rails_root>/lib/simple_form/label_nested_input.rb
module SimpleForm
module Components
module LabelInput
extend ActiveSupport::Concern
included do
include SimpleForm::Components::Labels
end
@sjava
sjava / devise.zh-CN.yml
Created December 14, 2011 09:22 — forked from fordguo/devise.zh-CN.yml
devise i18n for zh-CN
zh-CN:
errors:
messages:
expired: "您已过期,请重新申请"
not_found: "没有找到"
already_confirmed: "已经确认"
not_locked: "未锁定"
not_saved:
one: "因为1个错误导致此%{resource}保存失败:"
other: "因为%{count}个错误导致此%{resource}保存失败:"
@sjava
sjava / _form.html.erb
Created December 15, 2011 13:12 — forked from vjm/_form.html.erb
CRUD Devise Example
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@sjava
sjava / cracking.md
Last active August 29, 2015 14:10 — forked from vertexclique/cracking.md

MacOS

Build 3059

MD5: 59bab8f71f8c096cd3f72cd73851515d

Rename it to: Sublime Text

Make it executable with: chmod u+x Sublime\ Text

Sample service script for debianoids

Look at LSB init scripts for more information.

Usage

Copy to /etc/init.d:

# replace "$YOUR_SERVICE_NAME" with your service's name (whenever it's not enough obvious)
@sjava
sjava / forms.py
Created August 17, 2016 14:28 — forked from rombr/forms.py
How to add custom fields order to WTForms
from collections import OrderedDict
# ...
class OrderFormMixin(object):
'''
To apply add to Meta 'order' iterable
'''
def __init__(self, *args, **kwargs):
super(OrderFormMixin, self).__init__(*args, **kwargs)
@sjava
sjava / build-git.sh
Created September 29, 2016 15:24 — forked from pescobar/build-git.sh
compile git with openssl instead of gnutls
#!/usr/bin/env bash
# Clear out all previous attempts
rm -rf "/tmp/source-git/"
# Get the dependencies for git, then get openssl
sudo apt-get install build-essential fakeroot dpkg-dev -y
sudo apt-get build-dep git -y
sudo apt-get install libcurl4-openssl-dev -y
mkdir -p "/tmp/source-git/"
<dom-module id="nyaovim-app">
<template>
<style>
html,body {
background: transparent;
}
@keyframes blink {
0% {
@sjava
sjava / cropped_thumbnail.my
Created December 26, 2016 15:07 — forked from olooney/cropped_thumbnail.my
A "better" thumbnail algorithm for Python Image Library PIL Image
'''
PIL's Image.thumbnail() returns an image that fits inside of a given size (preserving aspect ratios)
but the size of the actual image will vary and is certainly not guaranteed to be the requested size.
This is often inconvenient since the size of the returned thumbnail cannot be predicted. The django-thumbs
library solves this for square thumbnails by cropping the image to a square and then resizing it. However,
this only works for exact squares.
This function generalizes that approach to work for thumbnails of any aspect ratio. The returned thumbnail
is always exactly the requested size, and edges (left/right or top/bottom) are cropped off to adjust to
make sure the thumbnail will be the right size without distorting the image.