Skip to content

Instantly share code, notes, and snippets.

View elundmark's full-sized avatar
💭
I may be slow to respond.

elundmark

💭
I may be slow to respond.
View GitHub Profile
@elundmark
elundmark / keyring_password.sh
Created July 19, 2012 14:11
Callable bash script that sets/gets passwords through gnome-keyring (Seahorse)
#!/bin/bash
# HAVE A LOOK AT https://gist.github.com/3135855 FIRST ON HOW THIS WORKS
# keyring_password.sh [ "name of key" [, "store-this_Password ]]
# It either echoes the stored password, or stores a new item
if [ ! "$1" ]; then
exit 1
fi
_PWNAME="$1" # A placeholder name for this password in the keychain
@elundmark
elundmark / apt_get_bashrc_aliases.sh
Created July 19, 2012 18:10
apt-get bashrc aliases collection
alias _sa='sudo apt-get'
alias _sai='sudo apt-get install'
alias _sar='sudo apt-get remove'
alias _sarp='sudo apt-get remove --purge'
alias _saa='sudo apt-get autoremove'
alias _saap='sudo apt-get autoremove --purge'
alias _sau='sudo apt-get update'
alias _sag='sudo apt-get upgrade'
alias _saug='sudo apt-get update && sudo apt-get upgrade'
alias _scaug='sudo apt-get update && sudo apt-get upgrade && sudo apt-get clean'
@elundmark
elundmark / deny_users_from_wpadmin.php
Created July 20, 2012 20:10
Wordpress: Deny user login for all non admin users
<?php
// deny user login for all non admin users
function restrict_access_admin_panel(){
global $current_user;
get_currentuserinfo();
// other tips I've read forgets that admin-ajax.php is used
// for ajax requests which breaks (almost) all plugins with ajax
if ($current_user->user_level < 4 && !defined('DOING_AJAX')) {
@elundmark
elundmark / url_extractor.py
Created July 21, 2012 07:31
Extract urls from webpage as list with python
#!/usr/bin/python -tt
# from: http://www.techgaun.com/2012/03/extracting-all-hyperlinks-from-webpages.html
import re, urllib2, sys
def main():
''' Usage: url_extractor.py "http://example.com/"
NOTICE: Intended for root urls; ie no */file or /subfolder/*
In that case you need to edit this file first
@elundmark
elundmark / functions.php
Created September 13, 2012 19:33
Include jQuery in Wordpress (Best practice)
<?php
// This replaces the included jQuery file from WP and uses the cdn hosted version from Google
// PLUS removes the ?ver=1.x.x from the url, making it more likely to be cached already
function rssv_scripts() {
global $wp_scripts;
if ( !is_a( $wp_scripts, 'WP_Scripts' ) )
return;
$wp_scripts->registered[jquery]->ver = null;
@elundmark
elundmark / jquery.startswith-pseudo-selector.js
Created September 27, 2012 18:14
Starts With - jQuery Custom Pseudo : selector
// Selects all matching elements who's first letter is 'x'
// Ignores any leading whitespace.
//
// Usage:
// <p>Hello!</p>
// <p>Honestly...</p>
// <p>Goodbye!</p>
//
// var allHes = $("p:startswith('h')"); // == [ "<p>Hello!</p>", "<p>Honestly...</p>" ]
@elundmark
elundmark / supress_errors.sh
Created October 16, 2012 00:40
GEdit Tools: Supress errors and warning to console
# When you edit your tools, "Manage external tools", wrap your code in brackets and send it to /dev/null
#!/bin/bash
{
#some code
} &>/dev/null
# this way you can suppress warnings otherwise sent to the console.
@elundmark
elundmark / node_js_template.js
Created October 22, 2012 12:03
Simple Node JS template
# usage in bash/sh
# $ NODERESULT=`node worker.js $(echo -n "Variable / file content" | base64 -w 0)`
# encode variable in bash and decode it in node using atob package
# , and finally decode the result in bash.
# $ NODERESULT=$(echo -n "$NODERESULT" | base64 --decode -w 0)
# This makes every argument given to node foolproof.
if ( !process.argv[2] ) {
throw new Error( "No valid argument given!" );
@elundmark
elundmark / if_jpeg.sh
Created October 23, 2012 02:27
Check for valid JPEG image
IMAGE=/path/to/image
if [[ "$(file -b $IMAGE)" =~ ^JPEG ]]; then
# EX: JPEG image data, JFIF standard 1.01
echo "Valid JPEG image"
fi
@elundmark
elundmark / wget_download_manager.sh
Created November 12, 2012 19:48
Batch Downloader in Bash using Wget
# paste into .bashrc or your aliases file
# Usage:
# $> downloadmanager "http://domain.com/file1.zip" "http://domain.com/file2.zip" "http://domain.com/file3.zip"
downloadmanager () {
if [ ! "$1" ] || [ ! "$@" ]; then
exit 1
fi
OLDDIR="$PWD"
DCOUNT=1