Skip to content

Instantly share code, notes, and snippets.

View steve-todorov's full-sized avatar

Steve Todorov steve-todorov

  • Carlspring Ltd.
  • Bulgaria
  • 08:58 (UTC +02:00)
View GitHub Profile
@steve-todorov
steve-todorov / 0_reuse_code.js
Last active October 18, 2015 20:47
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<?php
class DefaultController extends Controller
{
/**
* Dashboard page.
* @Permissions(perm="dashboard_view")
* @Route("/", name="ITEDashboardBundle_index")
* @Template()
* @return array
@steve-todorov
steve-todorov / ng-if-false.htm
Created September 25, 2015 23:54 — forked from bennadel/ng-if-false.htm
Creating A Pre-Bootstrap Loading Screen In AngularJS
<!-- BEGIN: Pre-Bootstrap Loading Screen. -->
<div ng-if="false">
<p>
This will show until the application is bootstrapped.
Then, the ngIf directive will immediately rip it out of
the page.
</p>
</div>
$filename="export.csv";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
$csv = fopen('php://output', 'w');
foreach($rows as $ind=>$row){
if($ind==0)
fputcsv($csv,array_keys($row));
@steve-todorov
steve-todorov / csv-to-array.php
Last active August 29, 2015 14:19
Get csv data as an array
<?php
set_time_limit(0);
ini_set('memory_limit',-1);
function parse_csv_assoc($str,&$f) {
if (empty($f)) { $f = str_getcsv($str); }
return @array_combine($f, str_getcsv($str));
}
@steve-todorov
steve-todorov / symfony-build-example.xml
Last active August 29, 2015 14:18 — forked from hectorsanjuan/build.xml
symfony-build-example.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="${projectName}" basedir="." default="build:main">
<!-- Properties -->
<property name="dir.app" value="${project.basedir}/app" />
<property name="dir.src" value="${project.basedir}/src" />
<property name="dir.build" value="${project.basedir}/app/build" />
<property name="dir.docs" value="${dir.build}/docs" />
<property name="dir.docs.phpdoc" value="${dir.docs}/phpdoc" />
<property name="dir.docs.docblox" value="${dir.docs}/docblox" />
<property name="dir.reports" value="${dir.build}/logs" />
<?php
namespace Acme\HelloBundle\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class MenuBuilder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
// /etc/polkit-1/rules.d/10-rules.rules
// PolKit rules to allow mounting, rebooting and network management without a password.
// User needs to be in storage, power and network groups.
polkit.addRule(function(action, subject) {
if (action.id.match("org.freedesktop.udisks2.") && subject.isInGroup("storage")) {
return polkit.Result.YES;
}
});

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

@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)) {