Skip to content

Instantly share code, notes, and snippets.

View athlan's full-sized avatar

Piotr Pelczar athlan

View GitHub Profile
@athlan
athlan / test-writable.php
Last active March 6, 2016 20:35
test-writable.php
<?php
var_dump(is_writable('./')); // check if this script can write something to directory
var_dump(get_current_user ()); // display user name that executing this PHP file</pre>
@athlan
athlan / AnnotationTypeInformationMapper.java
Created September 22, 2015 19:30
Spring Data Mongo custom _class value
package selly.spring.data.convert;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.config.BeanDefinition;
@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%
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;

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. :

@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() {
@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 / 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
<?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 / 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