Skip to content

Instantly share code, notes, and snippets.

View passion8's full-sized avatar

Paritosh Piplewar passion8

View GitHub Profile
@passion8
passion8 / breakRecursion.php
Created July 21, 2012 17:48
universal solution for breaking recursion loop ?
<?php
/*
Author : Paritosh Piplewar
Description : solution for recursion .
*/
function recursiveFunction(){
static $breaking_point = 1;
// here 5 is the extreme limit which breaks the function
if($breaking_point == 5){
break;
* Leap year concept : year is divided by 4 but not divided by 100.If is divided by both,then it must divided by 400 .
#include <iostream>
using namespace std;
int main(){
int year;
cin>>year;
if( (year % 4 == 0 && year % 100 != 0) || (year%100 == 0 && year % 400 == 0) ){
@passion8
passion8 / char.js
Created May 4, 2013 11:34
character count in query
(function($) {
$.fn.extend( {
limiter: function(limit, elem) {
$(this).on("keyup focus", function() {
setCount(this, elem);
});
function setCount(src, elem) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
@passion8
passion8 / step1.sh
Last active December 17, 2015 01:59
Fedena installation for ubuntu
sudo apt-get update -y
sudo apt-get upgrade -y
#install essential build tools
sudo apt-get -y install wget curl build-essential clang
sudo apt-get -y install bison openssl zlib1g
sudo apt-get -y install libxslt1.1 libssl-dev libxslt1-dev make
sudo apt-get -y install libxml2 libffi-dev libyaml-dev
sudo apt-get -y install libxslt1-dev autoconf libc6-dev
sudo apt-get -y install libreadline6-dev zlib1g-dev libcurl4-openssl-dev
sudo apt-get -y install libtool libcurl4-openssl-dev libssl-dev apache2-prefork-dev libapr1-dev libaprutil1-dev make
1.9.3p448 :083 > Date.beginning_of_week has
NameError: undefined local variable or method `has' for main:Object
from (irb):83
from /home/paritsoh/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /home/paritsoh/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /home/paritsoh/.rvm/gems/ruby-1.9.3-p448/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.3p448 :084 >
@passion8
passion8 / rescue_from_bug.rb
Created July 3, 2014 19:30
rescue_from_bug Rails bug
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
GEMFILE
system 'bundle'
end
require 'bundler'
class Product < ActiveRecord::Base
  include AlgoliaSearch
  algoliasearch do
   attribute find_the_attribute_name do
if foo
1
else
0
end
Mongo db console commands
//showing the existing dbs..
show dbs
//use test
switching to db test, (only creating it when actually adding new data)
//prompts the name of the working db now
db
//the fllw would prompt the count(), in the link2 collection, in the current db...
>db.links2.count()
{
"Version": "0.0.1",
"Time": "2015-02-12 09:48:22",
"Ack": "Ok",
"Offer": [ ]
}
{"responseEnvelope"=>{"timestamp"=>"2015-09-28T22:29:09.135-07:00", "ack"=>"Success", "correlationId"=>"45ae58603e954", "build"=>"17618768"}, "invoice"=>{"merchantEmail"=>"andrew-retailer@greentoe.com", "payerEmail"=>"a.k.ur.l.an.d@gmail.com", "number"=>"0014", "itemList"=>{"item"=>[{"name"=>"Canon EF 100-400mm f/4.5-5.6L IS USM Autofocus Lens", "quantity"=>1.0, "unitPrice"=>10.0, "discountAmount"=>0.0, "taxAmount"=>0.0}]}, "taxCalculatedAfterDiscount"=>false, "currencyCode"=>"USD", "invoiceDate"=>"2015-09-28T22:07:00.000-07:00", "dueDate"=>"2015-09-28T22:07:00.000-07:00", "paymentTerms"=>"DueOnReceipt", "discountAmount"=>0.0, "totalItemDiscountAmount"=>0.0, "taxInclusive"=>false, "shippingAmount"=>0.0, "shippingTaxAmount"=>0.0}, "invoiceDetails"=>{"status"=>"Paid", "totalDiscountAmount"=>0.0, "totalAmount"=>10.0, "origin"=>"API", "createdDate"=>"2015-09-28T22:16:49.000-07:00", "lastUpdatedDate"=>"2015-09-28T22:19:54.000-07:00", "firstSentDate"=>"2015-09-28T22:16:49.000-07:00", "lastSentDate"=>"2015-09-28T22: