Skip to content

Instantly share code, notes, and snippets.

View bibhuticoder's full-sized avatar
⌨️
Coding

Bibhuti Poudyal bibhuticoder

⌨️
Coding
View GitHub Profile
# coding=UTF-8
from __future__ import division
import re
# This is a naive text summarization algorithm
# Created by Shlomi Babluki
# April, 2013
class SummaryTool(object):
["Life isn’t about getting and having, it’s about giving and being.", "Kevin Kruse"]
["Whatever the mind of man can conceive and believe, it can achieve.", "Napoleon Hill"]
["Strive not to be a success, but rather to be of value.", "Albert Einstein"]
["Two roads diverged in a wood, and I—I took the one less traveled by, And that has made all the difference.", "Robert Frost"]
["I attribute my success to this: I never gave or took any excuse.", "Florence Nightingale"]
["You miss 100% of the shots you don’t take.", "Wayne Gretzky"]
["I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.", "Michael Jordan"]
["The most difficult thing is the decision to act, the rest is merely tenacity.", "Amelia Earhart"]
["Every strike brings me closer to the next home run.", "Babe Ruth"]
["Definiteness of purpose is the starting point of all achievement.", "W.
class PostListSerializer(serializers.Serializer):
slug = serializers.SerializerMethodField()
title = serializers.SerializerMethodField()
excerpt = serializers.SerializerMethodField()
# get translation to generate slug, title and excerpt
translation = None
def get_translation(self, post):
self.translation = post.translations.order_by('created_at').only('title', 'content')[0]
@bibhuticoder
bibhuticoder / attempt_1.rb
Last active May 1, 2019 03:00
Shared custom response form multiple actions in Ruby On Rails
class ExampleController < ApplicationController
def action_1
if res1.eql?(false)
render json: {message: 'Failed'}, status: 400 unless res_1
return
end
# rest of the logic....
render json: {data: '...'}, status: 200
end
class ExampleController < ApplicationController
def action_1
end
def action_2
end
def action_3
end
class ExampleController < ApplicationController
def action_1
if res1.eql?(false)
render json: {message: 'Failed'}, status: 400 unless res_1
return
end
# rest of the logic....
render json: {data: '...'}, status: 200
end
class ExampleController < ApplicationController
def action_1
res_1; return if performed?
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_2
res_1; return if performed?
# rest of the logic....
class ExampleController < ApplicationController
before_action :res1, only: [:action_1, :action_2]
before_action :res2, only: [:action_3, :action_4]
def action_1
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_2
{
"Version": "2012-10-17",
"Id": "Policy1593349925842",
"Statement": [
{
"Sid": "Stmt1593349907809",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
version: 0.2
phases:
install:
commands:
- npm i npm@latest -g
- pip install --upgrade pip
- pip install --upgrade awscli
pre_build:
commands: