Skip to content

Instantly share code, notes, and snippets.

View the-teacher's full-sized avatar
💻
Working remotely

Ilya N. Zykin the-teacher

💻
Working remotely
View GitHub Profile
@the-teacher
the-teacher / gist:5371759
Created April 12, 2013 12:45
smpp coding
message = text.encode("UTF-16BE").force_encoding("BINARY")
Gateway.send_mt(sender, receiver, message, data_coding: 8)
message = pdu.short_message.force_encoding('UTF-16BE').encode('UTF-8')
https://gist.github.com/zhengjia/428105
Class: Capybara::Node::Element
* [] - Retrieve the given attribute
* allow_reload!
* checked? - Whether or not the element is checked.
* click - Click the Element.
* disabled? - Whether or not the element is disabled.
* drag_to(node) - Drag the element to the given other element.
@the-teacher
the-teacher / gist:5411037
Created April 18, 2013 08:06
bash git prompt
// First file - git-completion.bash
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
@the-teacher
the-teacher / Gemfile
Created April 19, 2013 06:53
Integration tests
group :development, :test do
gem 'faker'
gem 'rspec'
gem 'rspec-rails'
end
group :test do
gem 'database_cleaner'
gem 'factory_girl_rails'
@the-teacher
the-teacher / wait_for_ajax.rb
Last active December 16, 2015 13:29
Capybara 2.0 Wait for ajax
require "timeout"
module WaitForAjax
def self.delay
@delay || 1
end
def self.delay= val
@delay = val
end
@the-teacher
the-teacher / example.coffee
Created April 24, 2013 08:45
Jquery plagin template
$('selector').smartDataInputs()
(($) ->
# e.keyCode e.shiftKey e.ctrlKey e.altKey e.metaKey
# keydown => keypress => keyup
$.fn.smartDataInputs = (options) ->
block = @
inputs = block.children('input')
params = $.extend {}, options
# STUB draft
Page.any_instance.stub(:save).and_return(false)
# CREATE draft
page = Page.create! valid_attributes
expect {
delete :destroy, {:id => page.to_param}, valid_session
}.to change(Page, :count).by(-1)
@the-teacher
the-teacher / gist:5563342
Created May 12, 2013 12:05
Rails 4 scope at has_many
has_many :attached_images, -> { where(attachment_content_type: "image/jpeg") }, as: :storage, class_name: AttachedFile
@the-teacher
the-teacher / drafts.rb
Created May 12, 2013 15:13
few MiniMagick drafts
image = MiniMagick::Image.open AttachedFile.last.path
image[:width]
image[:height]
image.auto_orient
image.resize "800x"
image.resize "x600"
image.format "gif"
c.rotate "-90>"
c.gravity "center"
c.compose "Over" # OverCompositeOp
@the-teacher
the-teacher / code.rake
Created June 7, 2013 01:30
multiple seeds This will allow you to do rake db:seed:x where “x” is a file in the db/seeds directory:
namespace :db do
namespace :seed do
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].each do |seed_file|
task_name = File.basename(seed_file, '.rb').intern
desc "Load the seed data from db/seeds/#{task_name}.rb"