Skip to content

Instantly share code, notes, and snippets.

@DenimTornado
DenimTornado / gist:6258367
Last active December 21, 2015 05:39 — forked from realmyst/gist:1262561
Склонение числительных на js
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
use:
declOfNum(count, ['товар', 'товара', 'товаров']);
@DenimTornado
DenimTornado / 0_reuse_code.js
Created September 30, 2013 22:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@DenimTornado
DenimTornado / translit+translate
Created September 30, 2013 22:08
From http://habrahabr.ru/post/195900/#comment_6794244 Перевести выделенное с автоматически определённого языка в выбранный Забиндить на хоткей как: «translate ru» или «translate en»
#!/bin/bash
source=$(xsel -o | sed "s/["'<>]//g")
trans="$(wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=${source}&sl=auto&tl=$1" | sed 's/[[["//' | cut -d " -f 1)"
url=`echo "$trans" | xclip -filter -selection clipboard`
notify-send -t 2500 "$source" "$trans"
var Anchors = document.getElementsByTagName("a");
for (var i = 0; i < Anchors.length ; i++) {
Anchors[i].addEventListener("click",
function (event) {
event.preventDefault();
if (confirm('Are you sure?')) {
window.location = this.href;
}
},
@DenimTornado
DenimTornado / new_gist_file.php
Created October 30, 2013 05:42
Отправка файла по почте From http://www.cyberforum.ru/php/thread55150.html
function xmail( $from, $to, $subj, $text, $filename) {
$f         = fopen($filename,"rb");
$un        = strtoupper(uniqid(time()));
$head      = "From: $from\n";
$head     .= "To: $to\n";
$head     .= "Subject: $subj\n";
$head     .= "X-Mailer: PHPMail Tool\n";
$head     .= "Reply-To: $from\n";
$head     .= "Mime-Version: 1.0\n";
$head     .= "Content-Type:multipart/mixed;";
@DenimTornado
DenimTornado / gist:8683708
Last active January 4, 2016 21:49
Safe font-family
font-family: Arial, Helvetica, sans-serif;
font-family: 'Arial Black', Gadget, sans-serif;
font-family: 'Bookman Old Style', serif;
font-family: 'Comic Sans MS', cursive;
font-family: Courier, monospace;
font-family: 'Courier New', Courier, monospace;
font-family: Garamond, serif;
font-family: Georgia, serif;
font-family: Impact, Charcoal, sans-serif;
font-family: 'Lucida Console', Monaco, monospace;
@DenimTornado
DenimTornado / check_if_ios
Last active August 29, 2015 14:04
Check user agent if iOS
var check_if_ios = function() {
var is_ios = /iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase());
if (is_ios) {
alert("iOS");
} else {
alert("not iOS");
}
}
@DenimTornado
DenimTornado / set_active_link
Created July 24, 2014 11:29
Set active link
@DenimTornado
DenimTornado / add_class
Last active August 29, 2015 14:04
Adding custom class to an element
var add_class = function(element, classname) {
var class_name = element.className;
//test for existance
if( class_name.indexOf( classname ) !== -1 ) {
return;
}
//add a space if the element already has class
if( class_name !== '' ) {
classname = ' '+classname;
}