Skip to content

Instantly share code, notes, and snippets.

View sunnyluthra's full-sized avatar

Sunny Luthra sunnyluthra

View GitHub Profile
@sunnyluthra
sunnyluthra / php_ssl_check.php
Created August 21, 2012 21:25
If a request arrived over ssl
<?php
if ('on' == $_SERVER['HTTPS']) {
//Yes, HTTPS request.
else{
//Http request
}
?>
@sunnyluthra
sunnyluthra / gist:3479002
Created August 26, 2012 13:05 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@sunnyluthra
sunnyluthra / CharacterLimiter.php
Created November 21, 2013 05:37
Limits the string based on the character count. Preserves complete words so the character count may not be exactly as specified.
<?php
/**
* Character Limiter
*
* Limits the string based on the character count. Preserves complete words
* so the character count may not be exactly as specified.
*
* @access public
* @param string
* @param integer
@sunnyluthra
sunnyluthra / array angl
Created December 17, 2013 04:33
Angl sample data
Array
(
[avatar] => https://s3.amazonaws.com/photos.angel.co/users/237099-medium_jpg?1382091520
[name] => Pathan Salman Khan
[bio] => Graduate from CSE, IITB. Active programmer in Codeforces, TopCoder and Hackerrank and other platforms.
[header_links] => Array
(
[linked_in-link] => http://www.linkedin.com/profile/view?id=84285625&trk=nav_responsive_tab_profile
[twitter-link] => https://twitter.com/pathansalman
[facebook-link] => http://www.facebook.com/pskhan1
@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",