Skip to content

Instantly share code, notes, and snippets.

View athlan's full-sized avatar

Piotr Pelczar athlan

View GitHub Profile
function getCookies() {
var c = document.cookie, v = 0, cookies = {};
if (document.cookie.match(/^\s*\$Version=(?:"1"|1);\s*(.*)/)) {
c = RegExp.$1;
v = 1;
}
if (v === 0) {
c.split(/[,;]/).map(function(cookie) {
var parts = cookie.split(/=/, 2),
name = decodeURIComponent(parts[0].trimLeft()),
<?php
public function listingResultFixedPostions(&$aResult) {
$fixedPositionsBuckets = array();
$count = count($aResult);
foreach($aResult as $key => &$row) {
if(isset($row['news_date_order_fixedposition'])) {
$pos = $row['news_date_order_fixedposition'];
@athlan
athlan / CEIDG grabber
Last active August 29, 2015 14:04
CEIDG grabber
// get into:
// https://prod.ceidg.gov.pl/CEIDG/ceidg.public.ui/Search.aspx
// and go go go!
var data = []
var urls = $('#MainContent_DataListEntities').find('a.searchITA').toArray().map(function(o) { return $(o).attr('href') })
urls = $.grep(urls, function(el, index) {
return index == $.inArray(el, urls);
});
var n = 0
@athlan
athlan / nodejs-unused-callback.js
Last active August 29, 2015 14:06
Nodejs Unused callback
var async = require('async')
var counter = 0
async.series([
function(callback) {
async.whilst(
function() { return counter < 5; },
function(whilstCallback) {
console.log('tick %d', counter)
@athlan
athlan / callback-once
Created October 14, 2014 11:00
Callback once
var sampleCallback = function(arg1) {
console.log('callback fired: %s.', arg1)
}
var CallbackOnce = function(callback) {
this.isFired = false
this.callback = callback
}
CallbackOnce.prototype.create = function() {

It's still a work in progress...

Intro

As William Durand was recently explaining in his SOS, he "didn't see any other interesting blog post about REST with Symfony recently unfortunately". After spending some long hours to implement an API strongly secured with oAuth, I thought it was time for me to purpose my simple explanation of how to do it.

Ok, you know the bundles

You might have already seen some good explanation of how to easily create a REST API with Symfony2. There are famous really good bundles a.k.a. :

function getTrilateration(position1, position2, position3) {
var xa = position1.x;
var ya = position1.y;
var xb = position2.x;
var yb = position2.y;
var xc = position3.x;
var yc = position3.y;
var ra = position1.distance;
var rb = position2.distance;
var rc = position3.distance;
@athlan
athlan / RemoveValuesUnderHistogramTreshold.m
Last active August 29, 2015 14:22
RemoveValuesUnderHistogramTreshold
function [ data_filtered ] = RemoveValuesUnderHistogramTreshold( data, percentageTreshold, numberOfHistogramBins )
%RemoveValuesUnderHistogramTreshold This function removes outstanding data variables that is
% under specific occurences threshold. The occurrences is partitioned
% by histogram method, equals bin size and fixes number of bins.
%
% data_filtered = RemoveValuesUnderHistogramTreshold(DATA, percentageTreshold, numberOfHistogramBins)
% (matrix) DATA : The vector with data
% (double) percentageTreshold : The occurences percentage (relative to maximum)
% that rejects outstanding values. Double value, e. g. 0.5 for under
% 50%
@athlan
athlan / autolike-facebook-wishes.js
Last active October 19, 2015 13:44
Facebook Like birthday wishes
/**
* Script to like all birthday wishes on timeline
* By Piotr Pelczar
*
* Usage:
* 1. Activate programming console in Google Chrome (F12)
* 2. Go to the console tab
* 3. Expand all wishes list (see more) as it reach end
* 4. Copy this script, paste and hit ENTER
* 5. MAGIC HAPPENS!!! Massive amount POST like requests are sent to Facebook
package com.selly.util.converter.json
import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
/**
* This class provides the inclusion and exclusion policy
* for Marshallers.
*
* Usage for exclusion policy:
* <code>