Move post code chunks to Gists
Also, remove highlight specific things from style.sass
This commit is contained in:
@@ -17,14 +17,6 @@ hosting the page yet. Until we get it in our hands, I did a trick.
|
||||
I enabled `mod_rewrite`, `mod_proxy` and `mod_proxy_http`, then added the following
|
||||
lines to my apache config:
|
||||
|
||||
{% highlight apache %}
|
||||
RewriteEngine on
|
||||
RewriteRule ^/$ http://172.16.72.131:8080/ [QSA,L,P]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^/(.*) http://172.16.72.131:8080/$1 [QSA,L,P]
|
||||
|
||||
Order allow,deny
|
||||
Allow from all
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/47680bfa44eb29708f20 %}
|
||||
|
||||
I’m not totally sure it’s actually secure, but it works for now.
|
||||
|
@@ -24,9 +24,7 @@ own role hierarchy service that implements `RoleHierarchyInterface`.
|
||||
So far so good, first tests. It soon turned out that if `User::getRoles()`
|
||||
returns a `DoctrineCollection` as it does by default, then the standard
|
||||
|
||||
{% highlight php %}
|
||||
$this->get('security.context')->isGranted('ROLE_ADMIN');
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/883ace4f35e440f6fe0f WhatEver.php %}
|
||||
|
||||
doesn’t work. I know, it should not be hard coded, as my roles and permission
|
||||
tables are dynamic, I have just tested. So I fixed my `User` entity so
|
||||
@@ -37,24 +35,12 @@ return the original collection, but I think it will never be used.
|
||||
After that, I had to implement some more features so I put this task away.
|
||||
Then, I tried to create my first ACL.
|
||||
|
||||
{% highlight php %}
|
||||
$securityIdentity = new RoleSecurityIdentity('ROLE_ADMIN');
|
||||
$objectIdentity = new ObjectIdentity('newsClass', 'Acme\\DemoBundle\\Entity\\News');
|
||||
$acl = $aclProvider->createAcl($objectIdentity);
|
||||
|
||||
$acl->insertClassAce($securityIdentity, MaskBuilder::MASK_OWNER);
|
||||
$aclProvider->updateAcl($acl);
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/883ace4f35e440f6fe0f WhatEver2.php %}
|
||||
|
||||
I was about to check if the user who is logged in has an `OWNER` permission on
|
||||
the `User` class.
|
||||
|
||||
{% highlight php %}
|
||||
$this->objectIdentity = new ObjectIdentity(self::OBJECT_ID, self::OBJECT_FQCN);
|
||||
if ($this->securityContext->isGranted('OWNER', $this->objectIdentity) === false) {
|
||||
throw new AccessDeniedException('You don’t have the required permissions!');
|
||||
}
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/883ace4f35e440f6fe0f WhatEver3.php %}
|
||||
|
||||
The ACL was defined based on a role, so everyone who had the `ROLE_ADMIN` role
|
||||
should gain access to the user listing page. But they didn’t. It took several
|
||||
|
@@ -17,10 +17,4 @@ the same name.
|
||||
|
||||
To change this, you will have to modify the `config.yml` file like this:
|
||||
|
||||
{% highlight yaml %}
|
||||
session:
|
||||
name: SiteSpecificSessionName
|
||||
lifetime: 3600
|
||||
{% endhighlight %}
|
||||
|
||||
I hope it helps some of you.
|
||||
{% gist gergelypolonkai/c695670ecca2809f7c93 %}
|
@@ -13,44 +13,10 @@ author:
|
||||
Few days ago I have struggled with a problem using Symfony2 configuration. I
|
||||
wanted to add the following kind of configuration to `config.yml`:
|
||||
|
||||
{% highlight yaml %}
|
||||
acme_demo:
|
||||
transitions:
|
||||
- { hc_cba: 180 }
|
||||
- { cba_hc: -1 }
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/30440e25f7a447730064 config.yml %}
|
||||
|
||||
The problem was that the stuff under `transitions` is dynamic, so those
|
||||
`hc_cba` and `cba_hc` tags can be pretty much anything. After hitting many
|
||||
errors, I came to the solution:
|
||||
|
||||
{% highlight php %}
|
||||
<?php
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('state_machine')
|
||||
->requiresAtLeastOneElement()
|
||||
->beforeNormalization()
|
||||
->ifArray()
|
||||
->then(function($values) {
|
||||
$ret = array();
|
||||
|
||||
foreach ($values as $value) {
|
||||
foreach ($value as $transition => $time) {
|
||||
$ret[] = array('transition' => $transition, 'time' => e);
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
})
|
||||
->end()
|
||||
->prototype('array')
|
||||
->children()
|
||||
->scalarNode('transition')->end()
|
||||
->scalarNode('time')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/30440e25f7a447730064 DynarrayConfiguration.php %}
|
||||
|
@@ -20,78 +20,9 @@ feature](https://developer.gnome.org/gobject/unstable/gtype-non-instantiable.htm
|
||||
obvious. Making the long story short, I have checked with the `GIO` sources for
|
||||
an example, and using that, I have created this small, working chunk:
|
||||
|
||||
{% highlight c %}
|
||||
#ifndef __WMUD_CLIENT_STATE_H__
|
||||
#define __WMUD_CLIENT_STATE_H__
|
||||
{% gist gergelypolonkai/47794b6fb94484f8160b client-state.h %}
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
/**
|
||||
* WmudClientState:
|
||||
* @WMUD_CLIENT_STATE_FRESH: Client is newly connected. Waiting for a login
|
||||
* player name
|
||||
* @WMUD_CLIENT_STATE_PASSWAIT: Login player name is entered, waiting for a
|
||||
* login password
|
||||
* @WMUD_CLIENT_STATE_MENU: Authentication was successful, player is now in the
|
||||
* main game menu
|
||||
* @WMUD_CLIENT_STATE_INGAME: Character login was successful, player is now
|
||||
* in-game
|
||||
* @WMUD_CLIENT_STATE_YESNO: Player was asked a yes/no question, and we are
|
||||
* waiting for the answer. client.yesNoCallback MUST be set at this point!
|
||||
* TODO: if wmudClient had a prevState field, and there would be some hooks
|
||||
* that are called before and after the client enters a new state, this
|
||||
* could be a three-state stuff, in which the player can enter e.g ? as
|
||||
* the answer, so they would be presented with the question again.
|
||||
* @WMUD_CLIENT_STATE_REGISTERING: Registering a new player. Waiting for the
|
||||
* e-mail address to be given
|
||||
* @WMUD_CLIENT_STATE_REGEMAIL_CONFIRM: E-mail address entered séms valid,
|
||||
* waiting for confirmation
|
||||
*
|
||||
* Game client states.
|
||||
*/
|
||||
typedef enum {
|
||||
WMUD_CLIENT_STATE_FRESH,
|
||||
WMUD_CLIENT_STATE_PASSWAIT,
|
||||
WMUD_CLIENT_STATE_MENU,
|
||||
WMUD_CLIENT_STATE_INGAME,
|
||||
WMUD_CLIENT_STATE_YESNO,
|
||||
WMUD_CLIENT_STATE_REGISTERING,
|
||||
WMUD_CLIENT_STATE_REGEMAIL_CONFIRM
|
||||
} WmudClientState;
|
||||
|
||||
|
||||
GType wmud_client_state_get_type (void) G_GNUC_CONST;
|
||||
#define WMUD_TYPE_CLIENT_STATE (wmud_client_state_get_type())
|
||||
|
||||
#endif /* __WMUD_CLIENT_STATE_H__ */
|
||||
{% endhighlight %}
|
||||
|
||||
{% highlight c %}
|
||||
#include "wmudclientstate.h"
|
||||
|
||||
GType
|
||||
wmud_client_state_get_type (void)
|
||||
{
|
||||
static volatile gsize g_define_type_id__volatile = 0;
|
||||
|
||||
if (g_once_init_enter(&g_define_type_id__volatile)) {
|
||||
static const GEnumValue values[] = {
|
||||
{ WMUD_CLIENT_STATE_FRESH, "WMUD_CLIENT_STATE_FRESH", "fresh" },
|
||||
{ WMUD_CLIENT_STATE_PASSWAIT, "WMUD_CLIENT_STATE_PASSWAIT", "passwait" },
|
||||
{ WMUD_CLIENT_STATE_MENU, "WMUD_CLIENT_STATE_MENU", "menu" },
|
||||
{ WMUD_CLIENT_STATE_INGAME, "WMUD_CLIENT_STATE_INGAME", "ingame" },
|
||||
{ WMUD_CLIENT_STATE_YESNO, "WMUD_CLIENT_STATE_YESNO", "yesno" },
|
||||
{ WMUD_CLIENT_STATE_REGISTERING, "WMUD_CLIENT_STATE_REGISTERING", "registering" },
|
||||
{ WMUD_CLIENT_STATE_REGEMAIL_CONFIRM, "WMUD_CLIENT_STATE_REGEMAIL_CONFIRM", "regemail-confirm" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
GType g_define_type_id = g_enum_register_static(g_intern_static_string("WmudClientState"), values);
|
||||
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
|
||||
}
|
||||
|
||||
return g_define_type_id__volatile;
|
||||
}
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/47794b6fb94484f8160b client-state.c %}
|
||||
|
||||
Still, it can be made more perfect by using the
|
||||
[glib-mkenums](http://developer.gnome.org/gobject/stable/glib-mkenums.html)
|
||||
|
@@ -14,13 +14,4 @@ Just insert it in your database, feed them two Google coordinates, and you get
|
||||
the distance in kilometres. If you happen to need it in miles, change the
|
||||
constant `12756.200` in the `RETURN` row to `7922.6` instead.
|
||||
|
||||
{% highlight sql %}
|
||||
DELIMITER $$
|
||||
|
||||
CREATE FUNCTION `haversine` (lng1 FLOAT, lat1 FLOAT, lng2 FLOAT, lat2 FLOAT)
|
||||
RETURNS float NO SQL DETERMINISTIC
|
||||
BEGIN
|
||||
SET @a = ABS(POWER(SIN(RADIANS(lat1 - lat2)) / 2, 2) + COS(RADIANS(lat1)) * COS(RADIANS(lat2)) * POWER(SIN(RADIANS(lng1 - lng2)) / 2, 2));
|
||||
RETURN 12756.200 * ATAN2(SQRT(@a), SQRT(1 - @a));
|
||||
END$$
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/bdad1cf2d410853bef35 %}
|
@@ -20,38 +20,7 @@ does the work for me. Its only requirements are git (of course), and the
|
||||
`column` command, which is pretty obviously present on every POSIX
|
||||
compliant systems (even OSX).
|
||||
|
||||
{% highlight sh %}
|
||||
#! /bin/sh
|
||||
|
||||
COLUMN=`which column 2> /dev/null`
|
||||
if test -z $COLUMN
|
||||
then
|
||||
echo "`column' is not found in PATH. Cannot continue."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
current_branch=`git rev-parse --abbrev-ref HEAD`
|
||||
|
||||
for branch in $(git for-each-ref --shell --format='%(refname)' refs/heads | sed -e s/^\'refs\\/heads\\///-e s/\'$//)
|
||||
do
|
||||
remote=`git config branch.$branch.remote`
|
||||
merge=`git config branch.$branch.merge | sed -e 's/^refs\/heads\///'`
|
||||
|
||||
[ x"$current_branch" == x"$branch" ] && echo -n '*'
|
||||
|
||||
echo -n "$branch"
|
||||
|
||||
if ! test -z $merge
|
||||
then
|
||||
echo -en "\t"
|
||||
echo -n $remote
|
||||
echo -n /
|
||||
echo -n $merge
|
||||
fi
|
||||
|
||||
echo
|
||||
done | $COLUMN -t
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/8af6a3e86b57dd4c250e %}
|
||||
|
||||
I just put it in my path, and `git branches-with-remotes` does the work!
|
||||
|
||||
|
@@ -20,14 +20,7 @@ In my other project,
|
||||
method. The following two rules in `Makefile.am` create `gswe-enumtypes.h`
|
||||
and `gswe-enumtypes.c`.
|
||||
|
||||
{% highlight make %}
|
||||
gswe-enumtypes.h: $(gswe_enum_headers) gswe-enumtypes.h.template
|
||||
$(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \
|
||||
gswe-enumtypes.h.tmp && mv gswe-enumtypes.h.tmp gswe-enumtypes.h
|
||||
gswe-enumtypes.c: $(gswe_enum_headers) gswe-enumtypes.h gswe-enumtypes.c.template
|
||||
$(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \
|
||||
gswe-enumtypes.c.tmp && mv gswe-enumtypes.c.tmp gswe-enumtypes.c
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/1e2fdedb136de3ca67f0 Makefile %}
|
||||
|
||||
`$(GLIB_MKENUMS)` is set in `configure` with
|
||||
`AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums])`.
|
||||
@@ -38,111 +31,6 @@ files, one for the header and one for the code. `$(gswe_enum_headers)`
|
||||
contains a list of all the header files that have enum types defined
|
||||
throughout the project.
|
||||
|
||||
{% highlight c %}
|
||||
/*** BEGIN file-header ***/
|
||||
/* gswe-enumtypes.h - Enumeration types for SWE-GLib
|
||||
*
|
||||
* Copyright © 2013 Gergely Polonkai
|
||||
*
|
||||
* SWE-GLib is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWE-GLib is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef __GSWE_ENUM_TYPES_H__
|
||||
#define __GSWE_ENUM_TYPES_H__
|
||||
#include <glib-object.h>
|
||||
{% gist gergelypolonkai/1e2fdedb136de3ca67f0 gswe-enumtypes.h %}
|
||||
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
/* enumerations from "@filename@" */
|
||||
|
||||
#include "@filename@"
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
GType @enum_name@_get_type(void);
|
||||
#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
|
||||
/*** END value-header ***/
|
||||
|
||||
/*** BEGIN file-tail ***/
|
||||
|
||||
#endif /* __GSWE_ENUM_TYPES_H__ */
|
||||
/*** END file-tail ***/
|
||||
{% endhighlight %}
|
||||
|
||||
{% highlight c %}
|
||||
/*** BEGIN file-header ***/
|
||||
/* gswe-enumtypes.c - Enumeration types for SWE-GLib
|
||||
*
|
||||
* Copyright © 2013 Gergely Polonkai
|
||||
*
|
||||
* SWE-GLib is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* SWE-GLib is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "swe-glib.h"
|
||||
#include "gswe-enumtypes.h"
|
||||
#include "@filename@"
|
||||
|
||||
/*** END file-header ***/
|
||||
|
||||
/*** BEGIN file-production ***/
|
||||
/* enumerations from "@filename@" */
|
||||
/*** END file-production ***/
|
||||
|
||||
/*** BEGIN value-header ***/
|
||||
GType
|
||||
@enum_name@_get_type(void)
|
||||
{
|
||||
static volatile gsize g_define_type_id__volatile = 0;
|
||||
|
||||
gswe_init();
|
||||
|
||||
if (g_once_init_enter(&g;_define_type_id__volatile)) {
|
||||
static const G@Type@Value values[] = {
|
||||
/*** END value-header ***/
|
||||
|
||||
/*** BEGIN value-production ***/
|
||||
{
|
||||
@VALUENAME@,
|
||||
"@VALUENAME@",
|
||||
"@valuenick@"
|
||||
},
|
||||
/*** END value-production ***/
|
||||
|
||||
/*** BEGIN value-tail ***/
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
GType g_define_type_id = g_@type@_register_static(
|
||||
g_intern_static_string("@EnumName@"),
|
||||
values
|
||||
);
|
||||
|
||||
g_once_init_leave(&g;_define_type_id__volatile, g_define_type_id);
|
||||
}
|
||||
|
||||
return g_define_type_id__volatile;
|
||||
}
|
||||
|
||||
/*** END value-tail ***/
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/1e2fdedb136de3ca67f0 gswe-enumtypes.c %}
|
@@ -16,25 +16,7 @@ displayed in small size, so this amount of precision was irrelevant, and
|
||||
these numbers took almost half of my SVG images’ size. So I created an
|
||||
Elisp defun to round these numbers to 2 decimals:
|
||||
|
||||
{% highlight common-lisp %}
|
||||
(defun get-number-at-point ()
|
||||
(interactive)
|
||||
(skip-chars-backward "0123456789.-")
|
||||
(or (looking-at "[0123456789.-]+")
|
||||
(error "No number at point"))
|
||||
(string-to-number (match-string 0)))
|
||||
|
||||
(defun round-number-at-point-to-decimals (decimal-count)
|
||||
(interactive "NDecimal count: ")
|
||||
(let ((mult (expt 10 decimal-count)))
|
||||
(replace-match (number-to-string
|
||||
(/
|
||||
(fround
|
||||
(*
|
||||
mult
|
||||
(get-number-at-point)))
|
||||
mult)))))
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/9c721ceda6d3079b4f05 %}
|
||||
|
||||
This finds the first digit of the number under point (the cursor), and
|
||||
reduces its digits to the given amount (or the number given with `C-u`). It
|
||||
|
@@ -43,9 +43,4 @@ his local repository with the same technique).
|
||||
[This StackOverflow answer](http://stackoverflow.com/a/17153598/1305139)
|
||||
suggests the very same, but with some aliases:
|
||||
|
||||
{% highlight ini %}
|
||||
|
||||
[alias]
|
||||
bisect-fixed = bisect bad
|
||||
bisect-unfixed = bisect good
|
||||
{% endhighlight %}
|
||||
{% gist gergelypolonkai/a98f4aab84659d60364e %}
|
||||
|
Reference in New Issue
Block a user