Skip to content

Instantly share code, notes, and snippets.

View sunnyluthra's full-sized avatar

Sunny Luthra sunnyluthra

View GitHub Profile
@sunnyluthra
sunnyluthra / git_shortcuts
Created January 31, 2014 05:45
Git Shortcuts to make life little bit easier
# Git shortcuts
alias g='git'
function ga() { git add "${@:-.}"; } # Add all files by default
alias gp='git push'
alias gpa='gp --all'
alias gu='git pull'
alias gl='git log'
alias gg='gl --decorate --oneline --graph --date-order --all'
alias gs='git status'

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

//To support android stock browser
/**
@private
Pushes a new state
@method pushState
@param path {String}
*/
pushState: function(path) {
@sunnyluthra
sunnyluthra / discourse_location.js
Created April 17, 2014 09:15
Changed discourse_location.js
/**
@module Discourse
*/
var get = Ember.get, set = Ember.set;
var popstateFired = false;
var supportsHistoryState = window.history && 'state' in window.history;
// Thanks: https://gist.github.com/kares/956897
var re = /([^&=]+)=?([^&]*)/g;
{
"posts": [{
"place": {
"fields": {
"title": {
"type": "_title", //predefined fields should start from underscore
"validation": {
"required": true
}
},
{
"status": "ok",
"count": 1,
"count_total": 1,
"pages": 1,
"posts": [
{
"id": 1,
"type": "post",
"slug": "hello-world",
@sunnyluthra
sunnyluthra / API Example
Last active August 29, 2015 14:01
API Example
{
foundPosts: "51",
totalPages: 13,
places:
[{
id: 202,
title: "Al-Bake",
description: "Al-Bake Shawarma, Afghani Chicken, Chicken Changezi, Malai Kofta, Chicken Talumin Soup",
smallPic: "http://10.23.2.207:8080/501/server/htdocs/content/uploads/2014/05/Al-Bake-84x84.jpg",
coverPic: "http://10.23.2.207:8080/501/server/htdocs/content/uploads/2014/05/Al-Bake-945x215.jpg",
@sunnyluthra
sunnyluthra / woocommerce-hide-price-logged-out.php
Created October 5, 2014 07:58
woocommerce-hide-price-logged-out.php
add_action('after_setup_theme', 'show_price_logged');
function show_price_logged($price) {
if (!is_user_logged_in()) {
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);
}
}
@sunnyluthra
sunnyluthra / redirect-android-ios.php
Created October 31, 2014 05:57
Redirect to playstore or appstore
define("PLAYSTORE_LINK", "");
define("APPSTORE_LINK", "");
sny_os_redirect();
function sny_os_redirect() {
if(sny_if_android() && PLAYSTORE_LINK){
header("Location: " . PLAYSTORE_LINK);
}elseif(sny_if_ios() && APPSTORE_LINK){
header("Location: ".APPSTORE_LINK);
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$uploadedfile = $_FILES['file'];
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
$wp_filetype = $movefile['type'];
$filename = $movefile['file'];
$wp_upload_dir = wp_upload_dir();