Skip to content

Instantly share code, notes, and snippets.

View lenart's full-sized avatar
🎯

Lenart Rudel lenart

🎯
  • Ljubljana, Slovenia
View GitHub Profile
@lenart
lenart / user-photo.php
Created June 12, 2011 09:53
Make User Photo use a single profile picture accross wordpress network
<?php
/*
Plugin Name: User Photo
Plugin URI: http://wordpress.org/extend/plugins/user-photo/
Description: Allows users to associate photos with their accounts by accessing their "Your Profile" page. Uploaded images are resized to fit the dimensions specified on the options page; a thumbnail image is also generated. New template tags introduced are: <code>userphoto_the_author_photo</code>, <code>userphoto_the_author_thumbnail</code>, <code>userphoto_comment_author_photo</code>, and <code>userphoto_comment_author_thumbnail</code>. Uploaded images may be moderated by administrators.
Version: 0.9.5.1
Author: <a href="http://weston.ruter.net/">Weston Ruter</a>
Original code by Weston Ruter <http://weston.ruter.net> at Shepherd Interactive <http://shepherd-interactive.com>.
Continued development and maintenance by Dave Wagner (cptnwinky) <http://dev.dave-wagner.com/>
@lenart
lenart / index.html.haml
Created September 24, 2013 20:01
Rails 3.x I18n pluralization for slovene language
# app/views/users/index.html.haml
%h1 Uporabniki
- # 1 uporabnik
= t(:user, count: 1)
- # 2 uporabnika
= t(:user, count: 2)
@lenart
lenart / deploy.rb
Created September 25, 2013 18:44
Capistrano tasks to use with figaro gem.
namespace :figaro do
desc "SCP transfer figaro configuration to the shared folder"
task :setup do
transfer :up, "config/application.yml", "#{shared_path}/application.yml", via: :scp
end
desc "Symlink application.yml to the release path"
task :symlink do
run "ln -sf #{shared_path}/application.yml #{latest_release}/config/application.yml"
end
@lenart
lenart / application.rb
Created October 9, 2013 09:34
SilentLogger for Rails 4 to keep NewRelic's requests out of the production log.
# config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require File.dirname(__FILE__) + '/../lib/silent_logger.rb'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
@lenart
lenart / 0_reuse_code.js
Last active August 29, 2015 14:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@lenart
lenart / gist:fb31fcd2521d6f72760c
Last active November 18, 2015 12:58
Get production database from heroku and update it locally
# Using [parity](https://github.com/thoughtbot/parity)
development restore production
development restore staging
# Steps for manual backup
heroku pg:backups capture --remote production
curl `heroku pg:backups public-url --remote production` > tmp/db.dump
@lenart
lenart / gist:039cfbd7e8f8cabd2391
Last active March 9, 2016 10:22
RSpec around filter for setting subdomain from example metadata
RSpec is absolutely flexible tool. One of its multitarget features is metadata. The main purpose of this feature is filtering and groupping examples by given attributes. You can found a lot of examples in article “Filtering examples in rspec-2”.
Recently I was faced with the need to test application behaviour depending on current subdomain. It was a group of examples so I need to use filters. Spec was similar to script below:
```ruby
feature "On custom subdomain", :subdomain => 'custom' do
scenario "homepage should change colorscheme to blue and use custom logo" do
...
end
@lenart
lenart / soft_deletable.rb
Created October 27, 2016 08:44
A Soft Delete concern
# Source by @Abs (http://stackoverflow.com/a/26855101)
module SoftDeletable
extend ActiveSupport::Concern
included do
default_scope { where(is_deleted: false) }
scope :only_deleted, -> { unscope(where: :is_deleted).where(is_deleted: true) }
end
def delete
@lenart
lenart / choose_password.html
Created February 1, 2017 18:55
Sample form for resetting password on parse-server (parseFrameURL)
<!--
parseFrameURL should point to this document.
Once the form is submitted it will:
- redirect to passwordResetSuccess if everything goes well
- redirect to invalidLink if data is invalid (eg. missing or invalid token, wrong email)
-->
<html>
<head></head>
<body>
<h1>Reset Your Password<span id='app'></span></h1>
@lenart
lenart / pre-request-scripts.js
Created November 15, 2018 12:28
Postman auto fetch oAuth access token
// Add this script to collection's pre-request scripts
// Collection -> Edit -> Pre-request Scripts
// Automatically fetch oAuth access_token and store it for 1 hour
update_token = pm.environment.get("token_time");
if (typeof(update_token) == "undefined" || update_token <= Date.now()) {
console.log("Fetching new oAuth access token for user");
pm.sendRequest({
url: pm.environment.get("host") + pm.environment.get("token_path"),