Skip to content

Instantly share code, notes, and snippets.

View Ulv's full-sized avatar
🤔
Working

Ulv Ulv

🤔
Working
View GitHub Profile
@Ulv
Ulv / slider.php
Created May 9, 2014 08:35
joomla 3: select last 6 featured articles
/*
*last 6 featured articles
*/
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')
->from($db->quoteName('#__content'))
->where($db->quoteName('featured') . ' = 1 ')
->order('created DESC');
@Ulv
Ulv / klumba_category_slider.php
Created May 25, 2014 08:39
joomla: fetch last 4 articles from current category subcategories
/*
* get subcategory ids
*/
$catID = $this->category->id;
$categories = JCategories::getInstance('Content');
$cat = $categories->get($catID);
$children = $cat->getChildren();
$children = array_map(function($el) {
return (array)$el;
@Ulv
Ulv / app.coffee
Created May 28, 2014 08:18
angularjs, coffeescript: app dataService (with promise)
# Usage examples:
#
# dataService.getTree().then((response)->
# if response
# $scope.list = response.data
#
# dataService.saveTree(nodeData)
.service "dataService", ($http) ->
delete $http.defaults.headers.common["X-Requested-With"]
@Ulv
Ulv / app.coffee
Created May 28, 2014 08:19
angularjs, coffeescript: app ng-update-hidden directive (use hidden form field with angular model)
# Usage: <input type="hidden" ng-model="elementid" ng-update-hidden />
.directive 'ngUpdateHidden', ->
(scope, el, attr) ->
model = attr["ngModel"]
scope.$watch model, (nv) ->
el.val nv
return
return
@Ulv
Ulv / menuBuilder.class.php
Created May 30, 2014 12:10
check is link
protected function isExternalLink($link)
{
return preg_match(
"%^((https?://)|(www\.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i",
$link) != false;
}
@Ulv
Ulv / newsreport.class.php
Created June 4, 2014 10:46
download and cache youtube video thumbnail
/*
* возвращает путь к локальному файлу - thumbnail'у видео с youtube
*/
$getYoutubeThumb = function ($videoUrl) {
/*
* скачивает в кэш thumbnail видео, возвращает полный путь к файлу
* Имя файла = md5(url)
*/
$downloadPic = function ($srcUrl, $getThumbUrl) {
return call_user_func(
@Ulv
Ulv / script.coffee
Created June 14, 2014 14:33
coffeescript parse GET query string
# разбор GET параметров
getParams = ->
query = window.location.search.substring(1)
raw_vars = query.split("&")
params = {}
for v in raw_vars
[key, val] = v.split("=")
params[key] = decodeURIComponent(val)
params
@Ulv
Ulv / script.coffee
Created June 14, 2014 14:34
coffeescript encode query string
encodeQueryData = (data) ->
ret = []
for d of data
ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d]))
ret.join "&"
@Ulv
Ulv / worldmapController.class.php
Created June 17, 2014 12:48
array_unique for multidimensional array
$regionsList = array_map("unserialize", array_unique(array_map("serialize", $regionsList)));
@Ulv
Ulv / gist:bb2ff2d1f3afec36b6db
Created June 27, 2014 07:00
clone git repository
# clone git repository
git clone --bare repository.git repoclone
cd repoclone
git push --mirror new-repository.git