Skip to content

Instantly share code, notes, and snippets.

View steve-todorov's full-sized avatar

Steve Todorov steve-todorov

  • Carlspring Ltd.
  • Bulgaria
View GitHub Profile
@steve-todorov
steve-todorov / gist:3671626
Created September 8, 2012 03:41
PHP Array key search for matching string.
<?php
/**
* Search through an array for a matching key.
*
* Examples:
* <code>
* $array = array(
* "database.name" => "my_db_name",
* "database.host" => "myhost.com",
@steve-todorov
steve-todorov / rawLinkToHtmlLink.php
Last active October 10, 2015 16:18
Replace links with html links.
@steve-todorov
steve-todorov / gist:5291540
Created April 2, 2013 11:22
Create zip files.
<?php
function create_zip($path, $save_as)
{
if (!extension_loaded('zip'))
throw new ErrorException('Extension ZIP has not been compiled or loaded in php.');
else if(!file_exists($path))
throw new ErrorException('The file/path you want to zip doesn\'t exist!');
@steve-todorov
steve-todorov / zip.php
Last active December 17, 2015 12:19
Create zip files.
<?php
function create_zip($path, $save_as)
{
if (!extension_loaded('zip'))
throw new ErrorException('Extension ZIP has not been compiled or loaded in php.');
else if(!file_exists($path))
throw new ErrorException('The file/path you want to zip doesn\'t exist!');
@steve-todorov
steve-todorov / bulgarian.regions.and.cities.sql
Created February 3, 2014 15:50
Bulgarian Regions & Cities (PostgreSQL)
-- Regions
CREATE TABLE regions(
region_id SERIAL PRIMARY KEY,
name character varying(255)
);
-- Cities
CREATE TABLE cities (
city_id SERIAL PRIMARY KEY,
region_id integer,
server {
listen 80;
server_name localhost;
root /home/website/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
try_files $uri @rewriteapp;
location @rewriteapp {
<?php
$countries = array("Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Island
@steve-todorov
steve-todorov / ssha.php
Created May 26, 2014 05:40
Create valid SSHA passwords for OpenLDAP
<?php
function ssha_password($password){
$salt = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',4)),0,4);
return '{SSHA}' . base64_encode(sha1( $password.$salt, TRUE ). $salt);
}
?>
@steve-todorov
steve-todorov / play-radio.php
Created November 29, 2014 01:34
play-radio.php
<?php
set_time_limit(-1);
$url = 'http://pub1.di.fm:80/di_chillstep_aac?bf3465a6e064e83f';
header("Content-type: audio/mpeg");
$handle = fopen($url, "r");
while($buffer = stream_get_contents($handle, 4096)) {

Put your rules in /etc/polkit-1/rules.d/*.rules.

See the polkit(8) manpage for rule syntax. (It's JavaScript.)

If you don't know the action name, run pkaction.

To test your rules, use pkcheck.

pkcheck -u -p $$ -a org.freedesktop.packagekit.upgrade-system