Skip to content

Instantly share code, notes, and snippets.

<?php
class Sentence{
static $phrase = "";
static $word1 = "eek";
static $word2 = "eep";
static $word3 = "yikis";
static function callRecursive($x){
//print $x."\n"; checking counter
<?php
//static variable make place in memory without initialization the object\
//static functions are class level function not object level, they cant access object level
class YourClass
{
protected $_attribute;
public function __construct() {
$this-> _attribute = 10;
<?php
$precision = 49;
ini_set("precision", $precision);
echo pi(); //will output 3.141592653589793115997963468544185161590576171875
?>
@nauman
nauman / ssltest.rb
Created April 18, 2012 03:20
openssl will work on windows with this code as well for pk12 type
#!/usr/bin/ruby
require 'openssl'
require 'base64'
if ARGV.length == 2
pkcs12 = OpenSSL::PKCS12.new(File.read(ARGV[0]), ARGV[1])
p pkcs12.certificate
else
puts "Usage: load_cert.rb <path_to_cert> <cert_password>"
end
fgcp_type = ProviderType.find_by_name('fgcp')
# Create a Username credential definition
CredentialDefinition.create!({
:name => 'username',
:label => 'Username',
:input_type => 'text',
:provider_type => fgcp_type
})
ENV['API_DRIVER'] = 'fgcp'
ENV['API_USERNAME'] = 'cert-dir'
ENV['API_PASSWORD'] = 'password'
load File.join(File.dirname(__FILE__), '..', '..', '..', 'lib', 'deltacloud_rack.rb')
#load File.join(File.dirname(__FILE__), '..', '..', 'common.rb')
Deltacloud::configure do |server|
server.root_url '/api'
server.version '0.5.0'
$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
require 'tests/drivers/fgcp/common'
require 'rubygems'
describe 'Deltacloud API' do
include Deltacloud::Test
it 'must returns valid drivers' do
get collection_url(:drivers)
last_response.status.must_equal 200
@nauman
nauman / common.rb
Created July 16, 2012 01:59
Common VCR testing
require 'vcr'
require 'addressable/uri'
require 'net/http'
require 'uri'
VCR.configure do |configure|
configure.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
configure.hook_into :webmock
#1. Change request before http request
@nauman
nauman / app.js
Created October 15, 2012 05:37
Titanium header - > title, content -> table, footer -> banner
Ti.UI.setBackgroundColor('#000');
var win = Ti.UI.createWindow({
backgroundColor: 'red',
exitOnClose: true,
fullscreen: false
});
var footerLabel = Ti.UI.createLabel({
text: 'Banner Rotation',
@nauman
nauman / application.rb
Created November 29, 2012 06:34
catch all exceptions
#catch all exceptions
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: :render_500
rescue_from ActionController::RoutingError, with: :render_404
rescue_from ActionController::UnknownController, with: :render_404
rescue_from ActionController::UnknownAction, with: :render_404
rescue_from ActiveRecord::RecordNotFound, with: :render_404
end
private