Skip to content

Instantly share code, notes, and snippets.

View neumachen's full-sized avatar
🏠
Working from home

Kareem H neumachen

🏠
Working from home
  • Bergen, Norway
  • 09:31 (UTC -12:00)
View GitHub Profile
# Potential solution to "Using accepts_nested_attributes_for with a belongs_to association, and using find_or_create_by_attr behaviour"
# http://stackoverflow.com/questions/2970255/using-accepts-nested-attributes-for-with-a-belongs-to-association-and-using-find
class Upload < AR:B
belongs_to :user
belongs_to :observed_property
belongs_to :sensor
attr_accessor :observed_property_attributes,
:sensor_attributes
attr_accessible :observed_property_attributes,
@paydro
paydro / git-rsync.sh
Created February 15, 2011 02:16
rsync changed files in a git repo to a remote server
git status -s | awk '{print $2}' | sed 's/\(.*\)/rsync -cav \1 user@remote.server.com:~\/\1/' | sh
@aaronjensen
aaronjensen / teamcity.rake
Created April 28, 2011 06:53
our teamcity rake.
task :teamcity => ['teamcity:clean', 'teamcity:setup', 'barista:brew', 'fork:spec', 'teamcity:cucumber', 'jasmine:ci']
namespace :teamcity do
task :setup do
RAILS_ENV = 'test'
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:schema:load'].invoke
end
@chrisbloom7
chrisbloom7 / README.md
Created June 6, 2011 07:16
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment

Note that this validation runs both after the file is uploaded and after CarrierWave has processed the image. If your base uploader includes a filter to resize the image then the validation will be run against the resized image, not the original one that was uploaded. If this causes a problem for you, then you should avoid using a resizing filter on the base uploader and put any specific size requirements in a version instead.

So instead of this:

require 'carrierwave/processing/mini_magick'

@senko
senko / onchange.sh
Last active July 14, 2023 07:54
OnChange - Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
@un33k
un33k / sed cheatsheet
Created August 22, 2011 13:28
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@nifl
nifl / grok_vi.mdown
Created August 29, 2011 17:23
Your problem with Vim is that you don't grok vi.

Answer by Jim Dennis on Stack Overflow question http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

Your problem with Vim is that you don't grok vi.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a simple statement which is, essentially, an abbreviation for 0 y$:

0 go to the beginning of this line. y yank from here (up to where?)

@guilleiguaran
guilleiguaran / assets.rake
Created September 1, 2011 04:26
Fixed rake assets:precompile task
desc "Compile all the assets named in config.assets.precompile"
task :precompile do
# We need to do this dance because RAILS_GROUPS is used
# too early in the boot process and changing here is already too late.
if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
ENV["RAILS_GROUPS"] ||= "assets"
ENV["RAILS_ENV"] ||= "production"
Kernel.exec $0, *ARGV
else
Rake::Task["environment"].invoke
@kirs
kirs / avatar_uploader.rb
Created September 24, 2011 07:33
Validation of image dimensions with CarrierWave
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
@nruth
nruth / gist:1264245
Last active August 23, 2021 01:57
Shared Capybara (or model setup) helpers for RSpec and Cucumber
# Let's assume you're driving Capybara in both RSpec request specs & Cucumber,
# for example you're using Cucumber as a design/documentation tool, and RSpec
# for the more boring integration tests.
# You don't want to duplicate your click-this-click-that helpers to e.g.
# log_in(username, password).
# You may also have model state setup code which can be shared/reused.
# Where can it go? How can it be loaded? I've been using the following approach:
#