Skip to content

Instantly share code, notes, and snippets.

View Ulv's full-sized avatar
🤔
Working

Ulv Ulv

🤔
Working
View GitHub Profile
@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
@Ulv
Ulv / script.coffee
Created August 30, 2014 12:45
linked selects in coffeescript
###
# связанные селекты
# secondarySelect всегда disabled кроме след. случаев:
# - в primarySelect есть значение
# - значение primarySelect != 0
###
$.fn.extend
bestdiplomSelect: (options) ->
@defaultOptions =
### пустое значение ###
###
# форма со связанными селектами
# - стилизация (https://github.com/Dimox/jQueryFormStyler)
# - цепляем функционал связанных селектов
# - геттеры
###
$.fn.extend
bestdiplomForm: (options) ->
@defaultOptions =
### селектор, к которому будем применять .styler() ###
@Ulv
Ulv / script.coffee
Created August 30, 2014 12:48
ajax load joomla rsform
###
# ajax подгрузка части формы
###
$.fn.extend
bestdiplomAjaxForm: (options) ->
@defaultOptions =
### основной селект, объект jQuery ###
primarySelect: $('#second')
loadTo: $('#ajaxload')