Skip to content

Instantly share code, notes, and snippets.


Giri Raj kayalshri

View GitHub Profile
# Copyright 2010-2019, 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
# 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 /
Last active Mar 15, 2019
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}
## Get Number of unique elements in dict
def sendSMS(clientId,msg):
cmd = """wget "" -O clientprofile.json""" % clientId
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 /
Created Mar 15, 2019
Python :: Count Unique Elements
## Problem : Get Number of unique elements in a list
x = ['f', 'e', 'e', 'f', 'f']
# output {'e': 2, 'f': 3}
o = {i:x.count(i) for i in x}
## Problem : Get Number of unique values in a dict
View pivot_table.sql
delimiter //
drop procedure if exists dynamic_view2//
create procedure dynamic_view2(in userid int, in sdate date,in edate date)
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;
View asana_api.html
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:",;
$("#a_username").html("<center><p>Hello,""</p></center>"); //image
if( == null){
$("#user_image").html("<center><img src='../img/default.png' class='img-circle' ></center>");
$("#user_image").html("<center><img src="" class='img-circle' ></center>");
View itebooks_info.php
$id = $_GET['id'];
$ch = curl_init($url);
$options = array(
kayalshri / twitter_connect.php
Created Sep 10, 2014
Simple twitter connector
View twitter_connect.php
function buildBaseString($baseURI, $method, $params)
$r = array();
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); //return complete base string
View gist:915748f00cdfd78371c3

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.


View credit_card_validate.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;