Skip to content

Instantly share code, notes, and snippets.

View sahanh's full-sized avatar

Sahan H. sahanh

  • Sri Lanka
View GitHub Profile
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"darsain/laravel-console": "dev-master",
"anonoz/fb-php-sdk-laravel-session": "dev-master",
"way/database" : "dev-master"
import os
from xlutils.copy import copy
from xlrd import open_workbook
from xlwt import Utils
import json
base_path = os.path.dirname(os.path.realpath(__file__))
file_path = base_path+'/eds_form.xls'
desti_path = base_path+'/final.xls'
raw_dump = base_path+'/export.json'
private function generateCacheKey($request)
{
$path = $request->getPathInfo();
$content = $request->getContent();
return 'app:'.sha1($path.$content);
}
@sahanh
sahanh / newrelic.php
Last active December 14, 2015 07:28
A class to implement newrelic in laravel
<?php
class NewRelic
{
public static function __callStatic($method, $params)
{
if (!extension_loaded('newrelic')) {
return null;
}
@sahanh
sahanh / gist:5624102
Created May 21, 2013 23:27
Getting controller and action before laravel populate them
$route = Router::route(Request::method(), URI::current());
$delegate = array_get($route->action, 'uses');
$reflector = new ReflectionClass('Controller');
$method = $reflector->getMethod('references');
$method->setAccessible(true);
$d = $delegate;
$p = $route->parameters;
$method->invokeArgs(null, [&$d, &$p]);
@sahanh
sahanh / ng-table-header-template
Created September 6, 2014 12:14
Using custom header in ng template
<table ng-table="tableParams" template-pagination="pagination" template-header="header" show-filter="false" class="table">
..
<script type="text/ng-template" id="header">
<ul class="btn-group pagination ng-table-pagination">
<li ng-class="{'disabled': !page.active}" ng-repeat="page in pages" ng-switch="page.type">
<a class="btn btn-xs btn-default" ng-switch-when="prev" ng-click="params.page(page.number)" href="">&laquo;</a>
<a class="btn btn-xs btn-default" ng-switch-when="first" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a>
<a class="btn btn-xs btn-default" ng-switch-when="page" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a>
@sahanh
sahanh / 0_reuse_code.js
Created January 5, 2017 10:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<script type="application/javascript">
var options = {
autoplay: true, //to stop autoplay of the video, make this false
facebookPixelId: '<your fb pixel id>', //put your facebook pixel id here
customEvent: false, //do you want to track this as a custom event, put it here
height: '390', //height of the video within quotes
width: '640', //width of the video within quotes
videoId: 'M7lc1UVf-VE', //id of the video within quotes
injectionProgress: 50 //the progress of the video that needs to trigger fb pixel
};
<script type="text/javascript">
var options = {
facebookPixelId: '45454545454',
customEvent: false,
injectionProgress: 50
};
$(document).ready(function(){ var timer; var player; var injected = false; $('iframe').each(function(){ var ele = $(this); if (ele.attr('id').indexOf('fitvid') < 0) { return; } var video = ele; var id = video.attr('id'); var src = video.attr('src') + '&enablejsapi=1'; video.attr('src', src); video.load(function(){ player = new YT.Player(id, { events: { 'onStateChange': onPlayerStateChange } }); }); function onPlayerStateChange(event) { if (event.data == YT.PlayerState.PLAYING) { var playerTotalTime = player.getDuration(); timer = setInterval(function() { var playerCurrentTime = player.getCurrentTime(); var playProgress = Math.ceil((playerCurrentTime / playerTotalTime) * 100); if (playProgress > options.injectionProgress && !injected) { if (!injected) { var eventData; if (options.customEvent !== false) { eventData = options.customEvent + '&cd[progress]='+ playProgress; } els