Skip to content

Instantly share code, notes, and snippets.

View sms-system's full-sized avatar
🏡
Alive

Serge Smirnov sms-system

🏡
Alive
  • TSARKA
  • Almaty
View GitHub Profile
@sms-system
sms-system / Вертикальное выравнивание
Last active August 29, 2015 13:56
Выравниваем дочерний div по центру (http://habrahabr.ru/post/73113/)
.parent {
width:500px;
height:400px;
background: #ffa;
}
.child {
display:-moz-inline-box;
display:inline-block;
vertical-align:middle;
zoom:1;
@sms-system
sms-system / downloadFile.js
Last active August 29, 2015 14:04
Скачать програмно файл по ссылке (http://pixelscommander.com/javascript/javascript-file-download-ignore-content-type/)
window.downloadFile = function(url,name) {
if (window.downloadFile.isChrome || window.downloadFile.isSafari) {
var link = document.createElement('a');
link.href = url;
if (link.download !== undefined){
var fileName = url.substring(url.lastIndexOf('/') + 1, url.length);
link.download = name?name:fileName;
}
if (document.createEvent) {
var e = document.createEvent('MouseEvents');
@sms-system
sms-system / print_r.js
Last active December 16, 2015 05:29
Эквивалент print_r() для javascript (http://htmlweb.ru/java/example/print_r.php)
function print_r(arr, level) {
var print_red_text = "";
if(!level) level = 0;
var level_padding = "";
for(var j=0; j<level+1; j++) level_padding += " ";
if(typeof(arr) == 'object') {
for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') {
print_red_text += level_padding + "'" + item + "' :\n";
@sms-system
sms-system / SpeedSite .htaccess
Created June 5, 2013 20:22
Ускорение загрузки сайта за счёт кэширования и gzip сжатия
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
AddEncoding gzip .gz
RewriteCond %{HTTP:Accept-encoding} !gzip
RewriteRule ^(.*)\.(css|js)?$ $1.src.$2 [QSA,L]
RewriteCond %{HTTP_USER_AGENT} Konqueror
RewriteRule ^(.*)\.(css|js)?$ $1.src.$2 [QSA,L]
<IfModule mod_headers.c>
<FilesMatch .*\.(js|css)$>
wait = (condition, successCallback, time, timeoutCallback, frequency=250, loadingCallback) ->
time *= 1000 / frequency if time?
waiting = setInterval ->
if condition.call()
successCallback.call()
else if time? && --time <= 0
timeoutCallback?.call()
else
loadingCallback?.call()
return
@sms-system
sms-system / ratio_box.css
Last active May 26, 2016 14:07
Ratio box in css
.a {
width: 900px;
position: relative;
}
.a:before {
content: '';
display: block;
width: 100%;
padding-bottom: 56.25%;
position: relative;
@sms-system
sms-system / MultiLanguage.py.js
Created June 4, 2016 19:44
Script runs in javascript and python
1//1;''' PYTHON
/*1//1'''
c=input()
n=int(c)
while n:print(c*n);n=n-1
1//1;'''
*/1//1'''
@sms-system
sms-system / demo.vue
Last active June 6, 2016 13:08
Vue.js Demo
<template lang="jade">
#app
h1 {{title | uppercase}}
ul(v-if="todos.length")
li.task(
v-for="task in tasks",
:class="{ done: task.done }",
@click="task.done = !task.done"
) {{task.content}}
p(v-else) Task List is empty.
@sms-system
sms-system / wrap
Last active June 30, 2016 11:04
Magic wraping for pug.js (JADE)
mixin wraper()
- var prevBuf = pug_html
- pug_html = ''
- block()
- wrapResult = pug_html
- pug_html = prevBuf
mixin wrap()
- var prevBuf = pug_html
- pug_html = ''
@sms-system
sms-system / throttle.js
Created September 16, 2016 08:01
Throttling function
const throttle = (callback, limit) => {
let wait = false
return function() {
if (!wait) {
callback.call(this)
wait = true
setTimeout(() => wait = false, limit)
}
}
}