Skip to content

Instantly share code, notes, and snippets.

View sagar290's full-sized avatar
🏠
Working from home

Sagar sagar290

🏠
Working from home
View GitHub Profile
@sagar290
sagar290 / angular_app.js
Created October 2, 2016 18:15 — forked from edwardhotchkiss/angular_app.js
Jekyll Live Search with AngularJS (blog)
/**
* Setup Module with `highlight` filter
*/
var JekyllApp = angular.module('JekyllApp', [], function($routeProvider) {
});
JekyllApp.filter('highlight', function() {
return function(text, filter) {
@sagar290
sagar290 / xmlToJson.js
Created July 12, 2017 04:27 — forked from chinchang/xmlToJson.js
Function to convert XML to JSON
// Changes XML to JSON
// Modified version from here: http://davidwalsh.name/convert-xml-json
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
// do attributes
if (xml.attributes.length > 0) {
@sagar290
sagar290 / repeatable-fields-metabox.php
Created September 21, 2017 00:58 — forked from helen/repeatable-fields-metabox.php
Repeating Custom Fields in a Metabox
<?
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {
@sagar290
sagar290 / embedded-file-viewer.md
Created December 2, 2017 10:06 — forked from tzmartin/embedded-file-viewer.md
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@sagar290
sagar290 / wp-auto-login-single-user.php
Created February 1, 2018 10:32 — forked from cliffordp/functions.php
Automatically login a single WordPress user upon arrival to a specific page. Redirect to home page once logged in. Prevent viewing the login page. Tested with WP 3.9.1. Used in functions.php
<?php
//Automatically login a single WordPress user upon arrival to a specific page.
//Redirect to home page once logged in and prevent viewing of the login page.
//Tested with WP 3.9.1. Used in functions.php
//Updated 2014-07-18 to resolve WP_DEBUG notice: "get_userdatabylogin is deprecated since version 3.3! Use get_user_by('login') instead."
//From http://tourkick.com/2014/wordpress-demo-multisite-db-reset/
function auto_login() {
//change these 2 items
$loginpageid = '1234'; //Page ID of your login page
@sagar290
sagar290 / Pull-and-Sync-Data-Between-Google-Doc-Spreadsheet-and-MySQL.gs
Created October 7, 2018 21:05
You can pull data from MySQL database to Google doc spreadsheet auto with just click of a button or scheduled time. This is great use for retrieving data in spreadsheet format.
// MySQL to Google Spreadsheet By Pradeep Bheron
// Support and contact at pradeepbheron.com
function myMySQLFetchData() {
var conn = Jdbc.getConnection('jdbc:mysql://127.0.0.1:3306/employee_db', 'username', 'pass'); // Change it as per your database credentials
var stmt = conn.createStatement();
var start = new Date(); // Get script starting time
@sagar290
sagar290 / ScoreController.php
Last active May 2, 2019 16:06
get user rank
<?php
$scores = Score::orderBy('score', 'desc')->get(); // get the sorted data
$user_id = 1; // we assigned the user id in $user_id variable
$output = array_search($user_id, array_column($scores, 'user_id')); // get he user index value by array search.
$position = $output + 1; // add 1 because its start with 0 index
return $position
@sagar290
sagar290 / ScoreController.php
Created May 2, 2019 16:30
Get position multiple variable
<?php
$scores = Score::orderBy('score', 'desc')->orderBy('time', 'asc')->get(); // get the sorted data
$user_id = 1; // we assigned the user id in $user_id variable
$output = array_search($user_id, array_column($scores, 'user_id')); // get he user index value by array search.
$position = $output + 1; // add 1 because its start with 0 index
return $position
@sagar290
sagar290 / ScoreController.php
Created May 2, 2019 17:03
get user position (best)
<?php
$user_id = 1; //assigned user id in $user id variable
$scores= Score::orderBy('score', 'desc')->orderBy('time', 'asc')->pluck('user_id')->toArray(); // get only user id in sorted ordered in term of score and time
$flip = array_flip($scores); // flip array index to value value to index
return $flip[(string)$user_id]+1; // add 1 because it will return index value
@sagar290
sagar290 / ImageController.php
Last active May 14, 2019 19:10
Get image as base 64 format and insert DB
<?php
class ImageController {
public function addEmployee(Request $request)
{
$pp = $request->pp;
$image_name = '';
if ($pp) {
list($type, $image) = explode(';', $pp);