Skip to content

Instantly share code, notes, and snippets.

Muluneh Awoke musen

Block or report user

Report or block musen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@musen
musen / prng.js
Created May 17, 2018 — forked from blixt/prng.js
A very simple, seedable JavaScript PRNG.
View prng.js
/**
* Creates a pseudo-random value generator. The seed must be an integer.
*
* Uses an optimized version of the Park-Miller PRNG.
* http://www.firstpr.com.au/dsp/rand31/
*/
function Random(seed) {
this._seed = seed % 2147483647;
if (this._seed <= 0) this._seed += 2147483646;
}
@musen
musen / 0_reuse_code.js
Created Sep 26, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@musen
musen / get_toc.php
Last active May 24, 2016
Extracts and returns table of contents (toc) and bookmarked content from any html.
View get_toc.php
<?php
function create_toc( $content ) {
preg_match_all( '/<h([1-6])(.*)>([^<]+)<\/h[1-6]>/i', $content, $matches, PREG_SET_ORDER );
global $anchors;
$anchors = array();
$toc = '<ol class="toc">'."\n";
$i = 0;
@musen
musen / generate_toc.php
Last active May 23, 2016
Generate table of contents from html.
View generate_toc.php
function _generate_toc( $content , $headings, $first_heading) {
preg_match_all( '/<h([' . $headings . '])(.*)>([^<]+)<\/h[' . $headings . ']>/i', $content, $matches, PREG_SET_ORDER );
global $anchors;
$anchors = array();
$toc = '<ul class="nav">'."\n";
$i = 0;
//add the fist anchor link
@musen
musen / generate_toc.php
Last active May 23, 2016
Generate table of contents from html.
View generate_toc.php
function _generate_toc( $content , $headings, $first_heading) {
preg_match_all( '/<h([' . $headings . '])(.*)>([^<]+)<\/h[' . $headings . ']>/i', $content, $matches, PREG_SET_ORDER );
global $anchors;
$anchors = array();
$toc = '<ul class="nav">'."\n";
$i = 0;
//add the fist anchor link
@musen
musen / Text Image mask with Rotating background images.markdown
Created Mar 29, 2016
Text Image mask with Rotating background images
View Text Image mask with Rotating background images.markdown
@musen
musen / extract_shortcode.php
Last active Dec 22, 2015
Extracts a shortcode tag from a post content and returns the content with target shortcode tag stripped out.
View extract_shortcode.php
<?php
/**
* Based on:
* https://codex.wordpress.org/Function_Reference/get_shortcode_regex
*/
function extract_shortcode($content, $tag) {
$shortcode_match = false;
@musen
musen / gist:00ba40aa5edf4fc151c2
Created Feb 2, 2015
Wordpress pre_get_posts action hook. Comes in handy when you would like to modify query variables before running archive queries.
View gist:00ba40aa5edf4fc151c2
//order products alphabetically and display all of them
function prefix_products_archive_modify( $query ) {
if ( is_post_type_archive('product') &&
! empty( $query->query['post_type']) &&
$query->query['post_type'] == 'product') {
$query->set( 'orderby', 'title' );
$query->set('order', 'ASC');
$query->set( 'posts_per_page', -1 );
}
You can’t perform that action at this time.