Skip to content

Instantly share code, notes, and snippets.

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

Rahul Arya rahularyan

🏠
Working from home
View GitHub Profile
@mikeschinkel
mikeschinkel / posts-ordered-by-meta.php
Created November 6, 2010 09:05
Class to extended WordPress' 3.0.x WP_Query to allow sorting by a meta_key.
<?php
/*
PostsOrderedByMetaQuery class that extends WP_Query and sorts posts meta_key
Author: Mike Schinkel (http://mikeschinkel.com)
This example works, just drop into the root of your website and call directly.
Use the class in your plugins or themes.
See: http://stackoverflow.com/questions/4111255/how-to-sort-a-query-posts-function-by-custom-field-while-limiting-posts-by-ano
@jeremyboggs
jeremyboggs / custom-post-type-flush-rewrite-rules.php
Created March 15, 2011 22:00
Pseudo-elegant way to flush rewrite rules after creating a custom post type.
<?php
/**
* Example for writing a WP plugin that adds a custom post type and flushes
* rewrite rules only once on initialization.
*/
/**
* On activation, we'll set an option called 'my_plugin_name_flush' to true,
* so our plugin knows, on initialization, to flush the rewrite rules.
*/
@coolaj86
coolaj86 / how-to-publish-to-npm.md
Last active June 9, 2024 23:19
How to publish packages to NPM

Getting Started with NPM (as a developer)

As easy as 1, 2, 3!

Updated:

  • Aug, 08, 2022 update config docs for npm 8+
  • Jul 27, 2021 add private scopes
  • Jul 22, 2021 add dist tags
  • Jun 20, 2021 update for --access=public
  • Sep 07, 2020 update docs for npm version
@falsecz
falsecz / gist:1675582
Created January 25, 2012 09:18
Node.JS php exec
// /usr/local/src/httpd-2.3.16-beta/support/ab -r -n 10000 -c 10 http://127.0.0.1:1327/
var http = require('http');
var sys = require('util')
var exec = require('child_process').exec;
var util = require('util');
var cnt = 0;
@bainternet
bainternet / gist:2175805
Created March 23, 2012 22:32
simple view counter for wordpress plugin
<?php
/*
Plugin Name: Simple Post Views
Plugin URI: http://en.bainternet.info
Description: Simple And lightweight plugin to track post views.
Version: 0.2
Author: Bainternet
Author URI: http://en.bainternet.info
*/
if ( !class_exists('PostViews')){
@Adirael
Adirael / fix-wordpress-permissions.sh
Created August 17, 2012 23:16
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
@zvineyard
zvineyard / html_form
Created August 30, 2012 15:29
PHP: Upload and Rename File
<form action="" enctype="multipart/form-data" method="post">
<input id="file" name="file" type="file" />
<input id="Submit" name="submit" type="submit" value="Submit" />
</form>
@codearachnid
codearachnid / sprintf_assoc.php
Last active December 10, 2015 16:39
vsprintf, sprintf, and printf do not allow for associative arrays to perform replacements `sprintf_assoc` resolves this by using the key of the array in the lookup for string replacement. http://php.net/manual/en/function.vsprintf.php
<?php
function sprintf_assoc( $string = '', $replacement_vars = array(), $prefix_character = '%' ) {
if ( ! $string ) return '';
if ( is_array( $replacement_vars ) && count( $replacement_vars ) > 0 ) {
foreach ( $replacement_vars as $key => $value ) {
$string = str_replace( $prefix_character . $key, $value, $string );
}
}
return $string;
<?php
// Resuable instance of WP_Query with preset $args
class Extended_WP_Query extends WP_Query {
function __construct( $args = array() ) {
$args = wp_parse_args( $args, array(
// some $args go here for reuse
) );
@jegtnes
jegtnes / sass_colorfunctions.php
Created June 6, 2013 08:43
A function attempting to rudimentary replicate SASS lighten/darken functions. Adapted from Frxstrem's answer on StackOverflow: http://stackoverflow.com/questions/3512311/how-to-generate-lighter-darker-color-with-php
<?php
function sass_darken($hex, $percent) {
preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i', $hex, $primary_colors);
str_replace('%', '', $percent);
$color = "#";
for($i = 1; $i <= 3; $i++) {
$primary_colors[$i] = hexdec($primary_colors[$i]);
$primary_colors[$i] = round($primary_colors[$i] * (100-($percent*2))/100);
$color .= str_pad(dechex($primary_colors[$i]), 2, '0', STR_PAD_LEFT);
}