Skip to content

Instantly share code, notes, and snippets.

Avatar

Giri Raj kayalshri

View GitHub Profile
View aws-textract-table.py
# 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 Mar 15, 2019
Interview QA in python
View pythonsimplesolutions.py
## 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
View sendsmsinaws.py
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 Mar 15, 2019
Python :: Count Unique Elements
View uniqueelements.py
## 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
View pivot_table.sql
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;
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:", 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>");
View itebooks_info.php
<?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 Sep 10, 2014
Simple twitter connector
View twitter_connect.php
<?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
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.

Twitter

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