Skip to content

Instantly share code, notes, and snippets.

View almokhtarbr's full-sized avatar
👋

almokhtar almokhtarbr

👋
  • 08:10 (UTC -04:00)
View GitHub Profile
@stereoscott
stereoscott / application_controller.rb
Last active January 31, 2021 14:08
Returning mobile views from rails, either by using a custom view path ("views_mobile") or by setting a custom request format.
class ApplicationController < ActionController::Base
before_filter :prepend_view_path_if_mobile
def mobile_request?
@mobile_request ||= (request.subdomains.first == domain_prefixes[:mobile])
end
helper_method :mobile_request?
def prepend_view_path_if_mobile
prepend_view_path Rails.root + 'app' + 'views_mobile' if mobile_request?
@lpar
lpar / flac2mp3.rb
Created January 26, 2013 22:58
Ruby script I use to convert FLAC files to MP3, and then copy the metadata across.
#!/usr/bin/env ruby
# encoding: UTF-8
# Convert FLAC files to mp3 files, keeping metadata from the FLAC files.
#
# Requires that FLAC (including metaflac) and LAME tools be installed
# and on the path.
#
# Takes any number of .flac files on the command line.
@alex-zige
alex-zige / gist:5795358
Last active June 8, 2023 07:49
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
@paulund
paulund / automatically-set-application-locale.php
Last active March 27, 2019 15:04
Automatically Detect Browser Language With PHP
<?php
$supportedLangs = array('en-GB', 'fr', 'de');
$languages = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach($languages as $lang)
{
if(in_array($lang, $supportedLangs))
{
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active May 28, 2024 17:41
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@JoshReedSchramm
JoshReedSchramm / collection_check_boxes.html.erb
Created October 27, 2013 00:05
An example of customizing collection_check_boxes in Rails 4. -- I'm working on converting a rails 3.2 app to Rails 4 and noticed that a couple of helpers from simple_form are now in the Rails core. I wanted to move away from dependencies as much as possible including getting rid of simple_form if possible so I went about converting the old view …
<%= f.collection_check_boxes :venue_ids, Venue.all, :id, :name, checked: Venue.all.map(&:id) do |b| %>
<span>
<%= b.check_box %>
<%= b.label %>
</span>
<% end %>
@awesome
awesome / ruby-multi-line-string-without-newlines-AND-ruby-multi-line-string-without-concatenation.rb
Created November 21, 2013 15:47
Ruby Multi-line String without Newlines —AND— Ruby Multi-line String without Concatenation
##
# by SoAwesomeMan
str =<<-EOS.gsub(/^[\s\t]*|[\s\t]*\n/, '') # no space "\s" for new line "\n"; kill tabs too
select awesome, awesome, awesome, awesome, awesome, awesome,
from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,
where cool cool cool cool cool cool cool cool cool cool cool'
EOS
# => "select awesome, awesome, awesome, awesome, awesome, awesome,from rad, rad, rad, rad, rad, rad, rad, rad, rad, rad, rad,where cool cool cool cool cool cool cool cool cool cool cool'"
str =<<-EOS.gsub(/^[\s\t]*/, '').gsub(/[\s\t]*\n/, ' ').strip # yes space "\s" for new line "\n"; kill tabs too
@simonista
simonista / .vimrc
Last active June 7, 2024 15:24
A basic .vimrc file that will serve as a good template on which to build.
" Don't try to be vi compatible
set nocompatible
" Helps force plugins to load correctly when it is turned back on below
filetype off
" TODO: Load plugins here (pathogen or vundle)
" Turn on syntax highlighting
syntax on
@lfender6445
lfender6445 / gist:9919357
Last active May 12, 2024 19:09
Pry Cheat Sheet

Pry Cheat Sheet

Command Line

  • pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)
  • pry -r ./config/environment.rb - load your rails into a pry session

Debugger

@tahirm
tahirm / xdebug.sh
Created April 18, 2014 19:42
Install/uninstall xdebug from pecl. #xdebug #apache2 Further notes for installing xdebug on ubuntu. http://ubuntuforums.org/showthread.php?t=525257
# install xdebug using pecl
$ sudo pecl install xdebug
# uninstall xdebug using pecl
$ sudo pecl uninstall xdebug