Skip to content

Instantly share code, notes, and snippets.

View kayalshri's full-sized avatar

Giri Raj kayalshri

View GitHub Profile
# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# This file is licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, either express or implied. See the License for the specific
@kayalshri
kayalshri / pythonsimplesolutions.py
Last active March 15, 2019 12:08
Interview QA in python
## Get Number of unique elements in a list
x = ['f', 'e', 'e', 'f', 'f']
# output: {'e': 2, 'f': 3}
# Solution
o = {i:x.count(i) for i in x}
print(o)
#-----------------------------------------------------------------------------------------------------
## Get Number of unique elements in dict
@kayalshri
kayalshri / sendsmsinaws.py
Created March 15, 2019 08:55
SMS Send via AWS
def sendSMS(clientId,msg):
cmd = """wget "https://nxyz.com/LATEST/001?module=profile&clientId=%s" -O clientprofile.json""" % clientId
os.system(cmd)
dataDict = None
with open('clientprofile.json') as bIN:
dataDict = json.load(bIN)
mobile = dataDict.get('mobile')
mstatus = dataDict.get('phoneStatus')
## Validate Mobile Status
if mstatus == 0:
@kayalshri
kayalshri / uniqueelements.py
Created March 15, 2019 07:29
Python :: Count Unique Elements
## Problem : Get Number of unique elements in a list
x = ['f', 'e', 'e', 'f', 'f']
# output {'e': 2, 'f': 3}
##Solution
o = {i:x.count(i) for i in x}
print(o)
## Problem : Get Number of unique values in a dict
@kayalshri
kayalshri / pivot_table.sql
Created December 26, 2014 11:30
Pivot table Procs
delimiter //
drop procedure if exists dynamic_view2//
create procedure dynamic_view2(in userid int, in sdate date,in edate date)
begin
declare finish int default 0;
declare cdate date;
declare str varchar(10000) default "select task_name,sub_task_name, ";
declare curs cursor for select creation_date from task where creation_date between sdate and edate group by creation_date;
declare continue handler for not found set finish = 1;
open curs;
@kayalshri
kayalshri / asana_api.html
Last active August 29, 2015 14:11
Asana Api
Login User Info:
================
asana.request("GET", "users/me?opt_fields=id,name,photo", function(ierr, userresponse) {
if (ierr){ console.error("Error:", ierr)}else{
//console.log("user data:", userresponse.data);
$("#a_username").html("<center><p>Hello,"+userresponse.data.name+"</p></center>"); //image
if( userresponse.data.photo == null){
$("#user_image").html("<center><img src='../img/default.png' class='img-circle' ></center>");
}else{
$("#user_image").html("<center><img src="+userresponse.data.photo.image_60x60+" class='img-circle' ></center>");
@kayalshri
kayalshri / itebooks_info.php
Created September 10, 2014 06:00
Get IT Books INFO
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$id = $_GET['id'];
$url="http://it-ebooks.info/book/$id/";
$ch = curl_init($url);
$options = array(
CURLOPT_RETURNTRANSFER => 1,
);
@kayalshri
kayalshri / twitter_connect.php
Created September 10, 2014 05:58
Simple twitter connector
<?php
function buildBaseString($baseURI, $method, $params)
{
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); //return complete base string

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@kayalshri
kayalshri / credit_card_validate.php
Created April 25, 2014 12:57
Credit Card Validation
<?php
function checkSum($ccnum) {
$checksum = 0;
for ($i=(2-(strlen($ccnum) % 2)); $i<=strlen($ccnum); $i+=2)
{
$checksum += (int)($ccnum{$i-1});
}
for ($i=(strlen($ccnum)% 2) + 1; $i<strlen($ccnum); $i+=2)
{
$digit = (int)($ccnum{$i-1}) * 2;