Skip to content

Instantly share code, notes, and snippets.

View jandudulski's full-sized avatar

Jan Dudulski jandudulski

View GitHub Profile
@jandudulski
jandudulski / .vimrc
Last active August 10, 2020 10:31
How to configure your editor to automatically strip trailing whitespaces and keep new line at the end of file?
if has("autocmd")
" remove trailing white spaces
autocmd BufWritePre * :%s/\s\+$//e
endif
@jandudulski
jandudulski / README
Created October 20, 2012 19:12 — forked from teamon/README
Custom form models
http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
O rly? Duplikacja atrybutów, duplikacja walidacji, pozdro z walidacja typu uniqueness of albo cokolwiek innego co hituje bazy per model.
class PhotosController < ApplicationController
before_filter :authenticate_user!
def create
current_user.photo = params[:file] || params[:qqfile]
data = if current_user.save
{
:success => true,
:photo => {
@jandudulski
jandudulski / ajax_rails.haml
Created June 29, 2012 17:01
Reinvet the wheel
# Instead of:
= link_to 'Fajne', fajny_path, id: 'fajny-url'
:javascript
$('#fajny-url').on('click', function() {
$.ajax('jakis/path', {
...
}).done(function(data) {
$('gdzieś').html(data);
@jandudulski
jandudulski / post-update
Created November 2, 2011 13:11
post-update hook which deploy on server when pushed changes to live branch
#!/bin/sh
branch=$(git rev-parse --symbolic --abbrev-ref $1)
if [ $branch == "live" ]
then
echo
echo "**** Pulling changes into live server ****"
echo
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@jandudulski
jandudulski / strem_notifier.rb
Created October 19, 2011 13:45
Stream notifier for earthquake
# coding: utf-8
Earthquake.init do
output do |item|
if item["_stream"] && item["text"]
notify item["text"], title: "#{item["user"]["name"]} (#{item["user"]["screen_name"]})"
end
end
end
@jandudulski
jandudulski / o.rb
Created July 21, 2011 15:29
Open tweet in a browser (Earthquake.gem plugin)
Earthquake.init do
command :o do |m|
begin
tweet = twitter.status(m[1])
browse "https://twitter.com/#{tweet['user']['screen_name']}/status/#{m[1]}"
rescue
puts 'invalid input'
end
end
end
@jandudulski
jandudulski / form.html
Created June 14, 2011 09:48
RangeDatepicker
<form id="search" data-range="1" data-offset="5">
<div class="wrapper">
<label>
First date:
<input type="text" value="" class="calendar first" readonly="readonly" />
</label>
<input type="hidden" value="" name="day" data-type="day" />
<input type="hidden" value="" name="month_1" data-type="month" />
</div>
<div class="wrapper">
git config --global alias.suck pull
git remote add my url
git branch dick
`git suck my dick` command (almost) ready to use!