Skip to content

Instantly share code, notes, and snippets.

#these are meant to be run in a REPL, and the java one in beanshell of something of the sort:
#ruby
[1,2,3,4].select{ |x| x.even? }
#python
[x for x in [1,2,3,4] if not x%2]
#or, more norvingly
filter(lambda x: not x%2, [1,2,3,4])
#clojure
@theshock
theshock / callback.length.js
Created August 4, 2011 14:01
Idea: JavaScript optimization using callback.length
// Идея в том, чтобы парсить колбеки на количество аргументов в заголовке и за счёт этого избежать ненужных вычислений.
/***************************************************************/
// Реализация приблизительно такая:
function afterCount (callback) {
var a = callback.length > 0 ? hardACount() : null;
var b = callback.length > 1 ? hardBCount() : null;
var c = callback.length > 2 ? hardCCount() : null;
callback(a,b,c);
@theshock
theshock / libcanvas.sh
Created January 10, 2013 19:19
Short Linux compilier for LibCanvas & AtomJS
shock@shock-notebook:~/dev/atomjs$ cat /usr/bin/libcanvas
#!/bin/sh
devPath=/home/shock/dev
atomPath=$devPath/atomjs
libcPath=$devPath/libcanvas
# project pathes
atomComp=$atomPath/atom-full-compiled.js
libcComp=$libcPath/libcanvas-full-compiled.js
// from
[UPDATE_ENTITY_EDITABLE_LOADING]: (state, { data: { entityId, editableFieldName }}) => ({
items: state.items.map(item => item.Id === entityId
? { ...item, [`loading${editableFieldName}`]: true }
: item),
error: null
})
// to
import _ from 'lodash-fp';
import { createFunctionsChain, groupProperties } from 'utils/collection';
export default function createStoreSection(prefix, samples) {
if (samples.some(sample => !sample)) {
throw new TypeError('Sample cant be empty');
}
const path = (suffix) => `${prefix}/${suffix}`;