Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
d1i1m1o1n / cyrtolat
Created April 14, 2015 09:07
Переводим кириллические символы в латинские соответствующие клавиатуре
//Если с английского на русский, то передаём вторым параметром true.
cyrtolat = (
function() {
var
rus = "й ц у к е н г ш щ з ф ы в а п р о л д я ч с м и т ь".split(/ +/g),
eng = "q w e r t y u i o p a s d f g h j k l z x c v b n m".split(/ +/g)
;
return function(text, engToRus) {
var x;
for(x = 0; x < rus.length; x++) {
@d1i1m1o1n
d1i1m1o1n / СНИЛС
Last active March 15, 2023 06:03
Проверка номера СНИЛС
<?php
if(!empty($_POST)){
// Массив сообщений об ошибках
$error = array();
// Удаляем тире и пробелы
$number = str_replace(array(" ", "-"),
array("", ""),
$_POST['number']);
$pattern = "|^\d{11}$|";
if(!preg_match($pattern, $number)){
@d1i1m1o1n
d1i1m1o1n / JQuery in console
Created April 20, 2015 11:15
JQuery in console
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
@d1i1m1o1n
d1i1m1o1n / Get osm_id by lan lon
Created April 26, 2015 06:13
Получаем osm_id по координатам
/**
* Получаем osm_id по координатам
* @param {string} lat lat
* @param {string} lon lon
* @return {int} osm_id
*/
function get_osmid_by_lat_lon(lat, lon){
jQuery.ajax({
url: 'http://overpass-api.de/api/interpreter',
type: 'POST',
@d1i1m1o1n
d1i1m1o1n / Get building by osm_id
Created April 26, 2015 06:24
Получаем массив координат здания по osm_id. Для конвертации xml в geojson используется https://github.com/tyrasd/osmtogeojson
/**
* Меняем местами lat и lon в массиве координат
* @param {array} coords массив координат
* @return {array} обработанный массив координат
*/
function swap_coords(coords) {
for (var i = coords.length - 1; i >= 0; i--) {
var first = coords[i][1];
coords[i][1] = coords[i][0];
coords[i][0] = first;
@d1i1m1o1n
d1i1m1o1n / Вычисление позиции курсора мыши
Created April 30, 2015 07:29
Данный сниппет поможет вам определить координаты пользовательского курсора практически во всех браузерах.
function getPosition(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
@d1i1m1o1n
d1i1m1o1n / Moodle get courses list with images
Created May 14, 2015 14:55
Moodle. Получаем список курсов с картинками.
<div class="courses">
<?$courses = get_courses();?>
<h1>Доступные курсы</h1>
<div class="courses-blocks">
<?foreach ($courses as $key => $course):?>
<?if( ! empty($course->idnumber)):
if ($course instanceof stdClass) {
require_once($CFG->libdir. '/coursecatlib.php');
$course = new course_in_list($course);
}
@d1i1m1o1n
d1i1m1o1n / Login form in modal
Created June 8, 2015 12:07
Bootstrap login form in modal
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<div id="login-overlay" class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Login to site.com</h4>
</div>
<div class="modal-body">
<div class="row">
@d1i1m1o1n
d1i1m1o1n / timeline css
Created June 8, 2015 12:14
Bootstrap timeline template
.timeline {
list-style: none;
padding: 20px 0 20px;
position: relative;
}
.timeline:before {
top: 0;
bottom: 0;
position: absolute;
content: " ";
@d1i1m1o1n
d1i1m1o1n / resume css
Created June 8, 2015 12:19
Bootrstrap resume template
/* uses font awesome for social icons */
@import url(http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css);
.page-header{
text-align: center;
}
/*social buttons*/
.btn-social{
color: white;