Skip to content

Instantly share code, notes, and snippets.

View kikill95's full-sized avatar

Kirill Gusyatin kikill95

View GitHub Profile
app.filter('l10n', function() {
// In the return function, we must pass in a single parameter which will be the data we will work on.
// We have the ability to support multiple other parameters that can be passed into the filter optionally
return function(input, key) {
// imagine that we have some variables with parsed JSONs
/* var JSONS = {
'ru': ruJSON,
'ua': uaJSON,
@kikill95
kikill95 / forEach.js
Created February 23, 2016 15:01
forEach for NodeList
// forEach method, could be shipped as part of an Object Literal/Module
var forEach = function (array, callback, scope) {
for (var i = 0; i < array.length; i++) {
callback.call(scope, i, array[i]); // passes back stuff we need
}
};
// Usage:
// optionally change the scope as final parameter too, like ECMA5
var myNodeList = document.querySelectorAll('li');
@kikill95
kikill95 / app.ts
Last active March 17, 2016 20:49
Klim
import {App, Platform} from 'ionic-framework/ionic';
import {HomePage} from './pages/home/home';
@App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
rootPage:any = HomePage;
import {Injectable} from 'angular2/core';
@Injectable()
export class VideoService {
getVideos() {
let videos = [
{
title: 'Canned Lightning',
src: 'vids/canned_lightning.mp4'
},
import {Page} from 'ionic-framework/ionic';
import {VideoService} from '../../services/videos';
@Page({
templateUrl: 'build/pages/home/home.html',
providers: [VideoService]
})
export class HomePage {
chosenVideo: any;
constructor(private video: VideoService) {
<ion-navbar *navbar>
<ion-title>
{{getChosenVideo().title || 'Holograms'}}
</ion-title>
</ion-navbar>
<ion-content class="home">
<ion-card *ngFor="#video of video.getVideos()">
<ion-card-header (click)="chooseVideo(video);">
{{video.title}}
@kikill95
kikill95 / gulpfile.js
Created March 20, 2016 20:03
browserify
var gulp = require('gulp'),
concat = require('gulp-concat'),
ngAnnotate = require('gulp-ng-annotate'),
uglify = require('gulp-uglify'),
autoprefixer = require('gulp-autoprefixer'),
sass = require('gulp-sass'),
minifyCss = require('gulp-minify-css'),
del = require('del'),
imagemin = require('gulp-imagemin'),
sourcemaps = require('gulp-sourcemaps'),
@kikill95
kikill95 / directive.js
Created April 4, 2016 18:53
Custom directive
angular.module('app', [])
.directive('ourDirective', function() {
return {
restrict: 'E',
transclude: false,
replace: true,
template: '<div>template</div>',
// templateURL: '../path/to/file.html',
// or function that returns the way for template
scope: {
@kikill95
kikill95 / test.js
Last active July 12, 2016 06:21
Example of work with DOM (events)
document.querySelector('body').innerHTML = '<div class="red"><div class="blue"><div class="green"></div></div></div><style>.red{background-color: red; width: 200px; height: 200px; padding-top: 50px; padding-left: 50px;} .blue{background-color: blue; width: 100px; height: 100px; padding-top: 50px; padding-left: 50px;} .green{background-color: green; width: 50px; height: 50px;}</style>';
var red = document.querySelector('.red'),
blue = document.querySelector('.blue'),
green = document.querySelector('.green');
red.addEventListener('click', function(event) {
console.log('red', event);
});
blue.addEventListener('click', function(event) {
event.stopPropagation();
console.log('blue', event);
@kikill95
kikill95 / tree.js
Created November 8, 2016 18:55
Recursion in JavaScript
var tree = {
father: 'papa_0', mother: 'mama_0', children: [
{
father: 'papa_1_0', mother: 'mama_1_0', children: [
{
father: 'papa_2_0', mother: 'mama_2_0', children: [
{
father: 'papa_3_0', mother: 'mama_3_0', children: []
},
{