Skip to content

Instantly share code, notes, and snippets.

@nazieb
nazieb / Laravel-Global-FIlter-Condition-for-Eloquent.php
Last active December 16, 2015 18:29
This code below is the example how to apply a global filter for Eloquent Models in Laravel (tested with LV 3.2.14). This will be useful if you have data that is stored in one table but has some classification defined by a column (in this example the column name is 'type') and you want to treat them differently in different models.
<?php
class Parents extends Eloquent {
const TYPE_A = 1;
const TYPE_B = 2;
static $type = null;
function __construct($type = null)
{
@nazieb
nazieb / base_model.php
Last active December 19, 2015 16:39
Base_Model for CodeIgniter. The idea is taken from Laravel's Eloquent ORM
<?php
/**
* Base Model to provide ORM-like CRUD operation wrapper
* Version: 1.1
*/
class Base_Model extends CI_Model {
protected $table = "";
protected $primary = "id";
protected $per_page = 20;
protected $order = "";
@nazieb
nazieb / FacebookFacade.php
Last active December 19, 2015 16:59
Facebook Facade in Laravel 4. Using Facade & Service Provider you can create a global "FB" class which you can call statically in Controllers / Routes / Views. For the example: <?php echo FB::getLoginUrl();
<?php namespace Facebook;
// app/libs/facebook/FacebookFacade.php
use Illuminate\Support\Facades\Facade;
class FacebookFacade extends Facade {
protected static function getFacadeAccessor() { return 'facebook'; }
}
@nazieb
nazieb / MY_Loader.php
Created August 21, 2013 10:51
Custom loader library for CodeIgniter to autoload database groups other than $default_group
<?php
class MY_Loader extends CI_Loader {
public function database($params = '', $return = FALSE, $active_record = NULL)
{
parent::database($params, $return, $active_record);
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/database.php'))
{
if ( ! file_exists($file_path = APPPATH.'config/database.php'))

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

@nazieb
nazieb / Dockerfile
Created July 28, 2016 13:08
Docker for API Blueprint builder
FROM debian:jessie
RUN apt-get update \
&& apt-get install -y git nodejs php5-common php5-cli --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g aglio
RUN git clone --recursive git://github.com/apiaryio/drafter.git \
&& cd drafter \
@nazieb
nazieb / shortener.go
Created March 3, 2017 08:03
ID shortener in Golang
package shortener
import (
"strings"
)
var shortenerDict = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789` // you can customize this, just make sure there's no duplicate chars
var shortenerBase = len(shortenerDict)
func ShortenID(ID int64) string {
const express = require('express');
const app = express();
const puppeteer = require('puppeteer');
const ua = require("useragent");
function isBot(userAgent) {
const agent = ua.is(userAgent);
return !agent.webkit && !agent.opera && !agent.ie &&
!agent.chrome && !agent.safari && !agent.mobile_safari &&
!agent.firefox && !agent.mozilla && !agent.android;
@nazieb
nazieb / app.js
Created February 2, 2019 15:17
AWS Lambda-Express example
const express = require("express");
const app = express();
app.get("/hello", (req, res) => {
res.json({
message: "Hello, World",
});
});
app.post("/ping", (req, res) => {
const express = require("express");
const app = express();
app.get("/hello", (req, res) => {
res.json({
message: "Hello, World",
});
});
app.post("/ping", (req, res) => {