Skip to content

Instantly share code, notes, and snippets.

View rohozhnikoff's full-sized avatar

Murad R. rohozhnikoff

  • Kyiv, Ukraine
View GitHub Profile
<?
function r() {
?><script>console.log.apply(console, ['php:'].concat(<? echo json_encode(func_get_args()); ?>))</script><?
}
?>
@rohozhnikoff
rohozhnikoff / makeClassSet.coffee
Last active August 29, 2015 14:11
declarative classSet for jquery (just for concept)
# global helper
makeClassSet = (classFunc) ->
return (params) ->
classArr = []
for className, exp of classFunc(params)
classArr.push(className) if exp
return classArr.join(' ')
# local helper
@rohozhnikoff
rohozhnikoff / ArrayFilterMap.coffee
Created December 15, 2014 22:31
Array::filterMap
Array::filterMap = (predicate) ->
acc = []
for el, i in @
res = predicate(el, i)
acc.push(res) if res?
return acc
@rohozhnikoff
rohozhnikoff / performer.coffee
Last active August 29, 2015 14:11
Function.prototype.perf (just for concept)
_ = require('underscore-contrib')
# ------------------------------------------ Helpers
middle = (x, y) -> (x + y) / 2
getter = _.curry2(_.flip(_.nth))
# ------------------------------------------ Perf definition
Function.prototype.perf = do ->
logs = {}
@rohozhnikoff
rohozhnikoff / randomize.coffee
Last active August 29, 2015 14:11
randomize
start = 10
maxV = 100000
# ---------------------------------------------
begin = process.hrtime()
getRandom = (acc, max) ->
while acc.indexOf(random) isnt -1
random = Math.floor(Math.random() * max) + 1
random
@rohozhnikoff
rohozhnikoff / git-backup.php
Created October 28, 2014 00:20
simple half-auto backup to git on php (just for concept)
<%
$default_branch = 'master';
$message = 'auto-commit';
if (isset($_GET['message']) && $_GET['message'] != '') {
$message = $_GET['message'];
}
$message .= 'from ' . date("Y-m-d H:i:s")
$results = array();
@rohozhnikoff
rohozhnikoff / findInArray.js
Last active August 29, 2015 14:07
simle and fast finder in js-array
function findInArray(array, callback) {
for (var i = 0, element = array[i], length = array.length; i < length; i++) {
if (callback.apply(callback, [element, i, array])) return element;
}
}
@rohozhnikoff
rohozhnikoff / look_methods_call
Last active August 29, 2015 14:06
observe all methods calls
# hard to perfomance
className = getClassName(@)
newProto = {}
_(@__proto__).each((value, name) =>
newProto[name] = do =>
if typeof value is 'function'
return =>
consoleMe = ['>>', [className, name].join('.')]
consoleMe.push '| call with', arguments if arguments.length > 0
console.log.apply console, consoleMe
@rohozhnikoff
rohozhnikoff / gist:9c4c1090b2963ee0dc7f
Created September 3, 2014 13:41
simple helper to add 's' if length more then 1
`import Ember from 'ember'`
oneormany = (length, value) ->
return "There are no #{value}s" if length is 0
suffix = if length > 1 then 's' else ''
return "#{length} #{value}#{suffix}"
OneormanyHelper = Ember.Handlebars.helper 'oneormany', oneormany
`export { oneormany }`
@rohozhnikoff
rohozhnikoff / equalHelper.coffee
Created September 3, 2014 13:40
block helper to check if arguments is equal
`import Em from 'ember'`
equal = (args..., options) ->
arr = for arg in args
value = @get(arg)
if typeof value isnt 'undefined' then value else arg
method = if _.isEqual.apply(_, arr) then 'fn' else 'inverse'
return options[method](@)