Skip to content

Instantly share code, notes, and snippets.

@harish-r
harish-r / Queue - Array Implementation.cpp
Created September 7, 2014 08:06
Queue Array Implementation in C++
#include<iostream>
#define MAX 5
using namespace std;
class Queue
{
public:
int front, rear;
int queue_array[MAX];
@harish-r
harish-r / Queue - Linked List Implementation.cpp
Created September 7, 2014 08:12
Queue - Linked List Implementation in C++
// Queue - Linked List Implementation
#include<iostream>
using namespace std;
class Node
{
public:
int data;
Node *next;
@magnific0
magnific0 / wp_usermeta.md
Last active February 6, 2025 02:30
Show and Edit User Meta in Wordpress

Show and Edit User Meta in Wordpress

Description

This simple procedure will allow you to:

  1. Display user meta fields under in the user list as additional columns (Users > All Users).
  2. Display these fields on user profiles.
  3. Edit these fields under user edit.

This method works completely without plugins and involves just some functions and hooks in functions.php. Plugins like "User Meta Display" achieve this to some level, but treat custom meta fields completely different from the regular fields. They are shown and edited in seperate environment and fail to show the meta data is a table list. This method integrates custom user meta along with regular user (meta).

@cgmartin
cgmartin / logging-middleware.js
Created May 24, 2015 01:43
Morgan JSON log format example
'use strict';
var morgan = require('morgan');
var os = require('os');
morgan.token('conversation-id', function getConversationId(req) {
return req.conversationId;
});
morgan.token('session-id', function getSessionId(req) {
return req.sessionId;
@mugifly
mugifly / jquery-ajax-with-node.js
Created July 9, 2015 11:52
Ajax with using jQuery on Node.js (Tested on Node.js v0.12.5)
var $ = require('jquery')(require('jsdom-no-contextify').jsdom().parentWindow);
// Support for Cross-domain request with using jQuery
// See: http://garajeando.blogspot.jp/2012/06/avoiding-xmlhttprequest-problem-using.html
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
$.support.cors = true;
$.ajaxSettings.xhr = function () {
return new XMLHttpRequest;
}
@mzabriskie
mzabriskie / nps.js
Created September 8, 2015 19:01
Calculate Net Promoter Score
// Expects an array of scores from 0-10
// Example: nps([10, 9, 10, 4]); -> 50
// See http://www.medallia.com/net-promoter-score/
function nps(scores) {
var promoters = 0;
var detractors = 0;
for (var i=0, l=scores.length; i<l; i++) {
if (scores[i] >= 9) promoters++;
if (scores[i] <= 6) detractors++;
@joshnuss
joshnuss / app.js
Last active August 4, 2025 12:16
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@evantoli
evantoli / GitConfigHttpProxy.md
Last active August 12, 2025 15:29
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@abhijeetchopra
abhijeetchopra / 0-README.md
Last active July 20, 2025 14:01
Creating automatic scheduled backup copies of your Google Sheets using Google Apps Script

How to "Schedule Automatic Backups" of your Google Sheets

This tutorial demonstrates how to use Google Apps Script to:

  • Create copies of the Google Sheet in the desired destination folder automatically at set intervals.

  • Append the time stamp with each backup file's name.

  • Adjust time trigger for backing up every day/hour/minute.

@jakehasler
jakehasler / upload.js
Last active January 3, 2024 12:52
POST an image as `multipart/form-data`
// Function form the react-native-image-picker library
ImagePicker.showImagePicker({ title: 'Select Image' }, (response) => {
// format the image data
const image = {
uri: response.uri,
type: 'image/jpeg',
name: 'myImage' + '-' + Date.now() + '.jpg'
}
// Instantiate a FormData() object
const imgBody = new FormData();