Skip to content

Instantly share code, notes, and snippets.

View we4tech's full-sized avatar

Hossain Khan we4tech

View GitHub Profile
@we4tech
we4tech / Gemfile
Created December 29, 2011 07:49
Sinatra with Rspec and custom rspec matcher
source 'http://rubygems.org'
gem 'sinatra'
group :test do
gem "rspec"
gem "rack-test"
end
@we4tech
we4tech / spec.rb
Created December 29, 2011 10:28
sample spec
describe 'auto increment' do
let!(:prev_widget) { FactoryGirl.create(:widget) }
let!(:new_widget) { FactoryGirl.create(:widget) }
subject { new_widget.sequence_no }
it { should be_incremented_by_one(prev_widget.sequence_no) }
end
@we4tech
we4tech / as3_netStream_from_dynamic_sources
Created April 27, 2012 09:57
ActionScript simple code snippet for getting NetStream outta Dynamic source
var trait:LoadTrait = pMediaPlayer.videoDisplay.mx_internal::videoPlayer.
media.getTrait(MediaTraitType.LOAD) as LoadTrait;
if (trait.__loader is RTMPDynamicStreamingNetLoader) {
var rtmpLoader:RTMPDynamicStreamingNetLoader =
trait.__loader as RTMPDynamicStreamingNetLoader;
if (rtmpLoader.__ns != null) {
mSensors.track(rtmpLoader.__ns, {
"stream": "livestreams/" + mCaption,
@we4tech
we4tech / spring-score.js
Created May 2, 2012 08:46
Spring Score Integration
var SpringAnalyticsJS = {
sensors: new SpringStreams("dbstream")
, screenX: 0
, screenY: 0
, duration: 0
, position: 0
, streamName: null
, uid: "test" + (new Date().getTime() * 10000 * Math.random())
@we4tech
we4tech / SpringAnalytics.as
Created May 2, 2012 09:26
Spring analytics integration
package com.easystream
{
import flash.display.DisplayObject;
import flash.events.NetDataEvent;
import flash.events.VideoEvent;
import flash.external.ExternalInterface;
import flash.net.NetStream;
import mx.controls.Alert;
import mx.core.mx_internal;
@we4tech
we4tech / spec_helper.rb
Created June 12, 2012 12:36
working spec_helper.rb with spork, factory_girl and devise
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
@we4tech
we4tech / product.rb
Created June 20, 2012 03:40
Sample flexi-model code
class Product
include FlexiModel
flexi_field :name, :string
flexi_field :price, :decimal
set_flexi_partition_id USER.store.id
end
@we4tech
we4tech / _your_model.rb
Created June 20, 2012 03:49
Fix 1 error(s) on assignment of multiparameter attributes for dynamic column or encapsulated column accessor
# Put it on your model instance
def column_for_attribute(name)
# Put your accessor name, in my case :value
if :value == name.to_sym
self.class.columns_hash[self.field.value_column.to_s]
else
self.class.columns_hash[name.to_s]
end
end
@we4tech
we4tech / page.rb
Created July 24, 2012 06:13
Sample active record model
class Page < ActiveRecord::Base
attr_accessible :body, :metadata, :title, :store_id
# Relationships
belongs_to :store
# Validations
validates_presence_of :title, :body, :store_id
# Scopes
@we4tech
we4tech / block-example.rb
Created July 24, 2012 09:58
Ruby closure - block code example
def say_hi_to(&block)
puts "Say hi #{block.call}"
end
say_hi_to { "hasan" }
#=> Say hi hasan