Skip to content

Instantly share code, notes, and snippets.

View yasyf's full-sized avatar

Yasyf Mohamedali yasyf

View GitHub Profile
@yasyf
yasyf / source.js
Created July 23, 2012 06:40
Javascript to display source
document.documentElement.innerHTML = '<html><head><link rel="stylesheet" href="http://google-code-prettify.googlecode.com/svn/branches/release-1-Jun-2011/styles/sunburst.css" /></head><body><pre class="prettyprint">&lt;!DOCTYPE html>\n&lt;html>\n' + document.documentElement.innerHTML.replace(/[<>]/g, function(m) { return {'<':'&lt;','>':'&gt;'}[m]}).replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>') + '\n&lt;/html></pre></body></html>'; var head= document.getElementsByTagName('head')[0];var script= document.createElement('script');script.type= 'text/javascript';script.src= 'http://css-tricks.com/examples/ViewSourceButton/prettify/prettify.js';head.appendChild(script);script.onload = function(){prettyPrint();};
@yasyf
yasyf / subs.php
Created August 1, 2012 01:36
WP-Subscription Example
<?php
header('HTTP/1.1 200 OK');
/**
* @package WordPress
* @var bool
*/
define('WP_USE_THEMES', false);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
$current_user = wp_get_current_user();
@yasyf
yasyf / openvpn-install.sh
Created August 1, 2012 20:29
OpenVPN Server on CentOS OpenVZ VPS
#!/bin/bash
#OpenVPN Server on CentOS OpenVZ VPS Script by Yasyf Mohamedali (http://blog.yasyf.com/2012/08/01/openvpn-server-on-a-centos-openvz-vps)
#Adapted from various scripts around the net, including http://www.openvz.ca/blog/2010/11/18/setup-tuntap-openvpn-server-openvz-5-minutes/
#https://gist.github.com/3230440
tunstate=`cat /dev/net/tun`
if [ "$tunstate" = "cat: /dev/net/tun: Permission denied" ]
then
clear
echo "Sorry, but it seems that TUN/TAP is not enabled on your VPS."
exit
@yasyf
yasyf / rss-diff.sh
Created August 4, 2012 09:58
Monitoring RSS feeds for changes from bash
#!/bin/bash
show_usage()
{
echo "Usage: rss-diff -o original -f feed -t trim"
exit
}
MINARGS=2
case $1 in
"-h"|"--help") show_usage; return 1; ;;
esac
@yasyf
yasyf / WebReader.java
Created October 18, 2012 02:19
JWebPass WebReader Class
package jwebpass;
import java.io.IOException;
import java.net.NoRouteToHostException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Scanner;
/**
@yasyf
yasyf / JLog.java
Created October 18, 2012 03:56
JLog - The Calculator log Button
package jlog;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
/**
*
* @author yasyf
*/
public class JLog {
@yasyf
yasyf / back.php
Created October 21, 2012 00:42
Simple, Complete Incremental WordPress Backup
<?php
header("Cache-Control: no-cache, must-revalidate");
header('HTTP/1.1 200 OK');
function wpcomplete_searchBackups($dir) {
global $searchnames;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != "index.php" && $file != 'database.sql' && $file != '.wpcmanifest' && is_file($dir.'/'.$file)) {
$searchnames[] = $dir.'/'.$file;
@yasyf
yasyf / Favicon
Last active December 11, 2015 20:09
<link rel="icon" type="image/x-icon" href="http://cache.yasyf.com/favicon.ico" />
@yasyf
yasyf / ldap.php
Last active December 11, 2015 20:09
<?php
/** {{{ http://code.activestate.com/recipes/101525/ (r1) */
$ldapconfig['host'] = 'localhost';
$ldapconfig['port'] = NULL;
$ldapconfig['basedn'] = 'dc=localhost,dc=com';
$ldapconfig['authrealm'] = 'My Realm';
function ldap_authenticate() {
global $ldapconfig;
global $PHP_AUTH_USER;
@yasyf
yasyf / contact.php
Last active December 12, 2015 01:18
Simple Math Spam Check
<?php
$one = rand(1,10); $two = rand(1,10);
define('_def_check_spam', "$one + $two =");
?>
<input type="text" name="contact-spam-check" id="contact-spam-check" value="<?php echo _def_check_spam; ?>" onfocus="clearInput(this,'focus','<?php echo _def_check_spam; ?>')" onblur="clearInput(this,'blur','<?php echo _def_check_spam; ?>')" />
<input type="hidden" name="contact-spam-answer" id="contact-spam-answer" value="<?php echo $one+$two; ?>" />