Skip to content

Instantly share code, notes, and snippets.

View ybigus's full-sized avatar

Yaroslav Bigus ybigus

View GitHub Profile
@ybigus
ybigus / frequency.hs
Created April 14, 2017 07:23
frequency
count:: Int -> [Int] -> Int
count x arr = length $ filter (\i -> i == x) arr
freq:: [Int] -> [Int] -> [(Int, Int)]
freq [] _ = []
freq (x:xs) acc = [(x, count x acc + 1)] ++ freq xs (x: acc)
example:: [(Int, Int)]
example = freq [1,2,1,2,4,2,1] []
$.when.apply(this, deffered_params).done(function(){
//let's start our party
});
var deffered_params = [];
deffered_params.push(load_geometry('pawn'));
deffered_params.push(load_geometry('rook'));
deffered_params.push(load_geometry('knight'));
deffered_params.push(load_geometry('bishop'));
deffered_params.push(load_geometry('queen'));
deffered_params.push(load_geometry('king'));
deffered_params.push(load_texture('chess_board_texture', 'chessboard.jpg'));
deffered_params.push(load_texture('white_cell','white_cell.jpg'));
deffered_params.push(load_texture('black_cell','black_cell.jpg'));
var load_texture = function(name, path){
var d = $.Deferred();
THREE.ImageUtils.loadTexture('assets/textures/'+path, THREE.UVMapping(), function(image){
textures[name] = image;
d.resolve();
});
return d.promise();
}
var load_geometry = function(name){
var womanHeightList = [155,157,160,163,165,168,170,171,173,175,178,180,183];
var increaseButtonStream = $('.btn-size.add').asEventStream('click');
var decreaseButtonStream = $('.btn-size.delete').asEventStream('click');
var counterStream = increaseButtonStream.map(1).merge(decreaseButtonStream.map(-1)).scan(0, function (acc, x){
var sum = acc + x;
if (sum<0) sum = womanHeightList.length-1;
if (sum>womanHeightList.length-1) sum = 0;
return sum;
});
var dragStartStream = element.asEventStream('mousedown');
var dragEndStream = $(window).asEventStream('mouseup');
var dragStream = dragStartStream.flatMap(function(e){
$('.human,.product').css('z-index','1');
element.css('z-index','99');
return $(window).asEventStream('mousemove').map(function(event){
event.startX = e.offsetX;
event.startY = e.offsetY;
return event;
}).takeUntil(dragEndStream);
from django.shortcuts import render
from django.http import HttpResponse, HttpRequest
from main.models import Track
from django.db.models import Q
def index(request):
if request.method == 'POST':
term = request.POST["term"]
tracks = Track.objects.filter(Q(name__icontains=term)| Q(artist__icontains=term)).order_by('-rate')[:10]
context = {'tracks': tracks, 'term': term}
function moveHero(){
heroWrap.setLinearVelocity(
new THREE.Vector3(0, 0, 0)
);
heroWrap.__dirtyPosition = true;
if(moveTop){
heroWrap.position.x += Math.cos( hero.rotation.y) ;
heroWrap.position.z -= Math.sin( hero.rotation.y) ;
if(currentAnimation!='run')
hero.playAnimation( 'run', 6 );
function addHero(scene) {
var boardMaterial = Physijs.createMaterial(new THREE.MeshLambertMaterial({ color: 0xffffff }), 0, 0);
heroWrap = new Physijs.SphereMesh(
new THREE.SphereGeometry(10,32,32),
boardMaterial,
1000
);
heroWrap.visible=false;
heroWrap.position.set(50, 10, 50);
function loadHero(){
var loader = new THREE.JSONLoader();
loader.load( 'content/hero.js', function( h, m ) {
//smooth skin
h.computeMorphNormals();
materialTexture = new THREE.MeshPhongMaterial({
color: 0xffffff, specular: 0x111111, shininess: 50, wireframe: false,
shading: THREE.SmoothShading, map: texture, morphTargets: true, morphNormals: true, metal: false
});