Skip to content

Instantly share code, notes, and snippets.

View dmshvetsov's full-sized avatar
🪄

Dmitry Shvetsov dmshvetsov

🪄
View GitHub Profile
@dmshvetsov
dmshvetsov / telLinkTag.php
Created May 15, 2014 07:40
Make tel: anchor tags from telephones string
function telLinkTag($str = '') {
$delimeter = ', ';
$tels = explode($delimeter, $str);
$res = array();
foreach($tels as $tel) {
$invalidChar = array('(', ')', ' ', '-');
array_push($res, '<a href="' .
'tel:+' . str_replace($invalidChar, '', $tel) .
'">' .
$tel .
@dmshvetsov
dmshvetsov / subsiteLink.php
Created October 10, 2014 06:49
A function for proprietary CMS that return
@dmshvetsov
dmshvetsov / gem_pg_install_for_fancycase.sh
Last active August 29, 2015 14:08
For PostrgreSQL installed from OS X packages 9.3 and bundle
gem install pg -v '0.17.1' -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
@dmshvetsov
dmshvetsov / next_n_work_days.rb
Last active August 29, 2015 14:16
Collect only 'n' weekdays including current date, but no weekends
require 'date'
def next_n_work_days n
today = Date.today
number_of_weekends_days = ((n / 5) *2)
(1..(number_of_weekends_days + n) - 1).reduce([today]) do |days, plus_num_days|
day = today + plus_num_days
# or
# day = days.last.next
@dmshvetsov
dmshvetsov / file_read_stup.rb
Created May 6, 2015 05:45
RSpec File read stub by Anatoly Spektor
data = {:name => "test" , :description => "test"}.to_json
allow(File).to receive(:read).and_return(data)
@dmshvetsov
dmshvetsov / react_ujs.js
Created December 10, 2015 05:09 — forked from rescribet/react_ujs.js
Non-global react_ujs
/*globals React, Turbolinks*/
/* Modified react_ujs to prevent the components polluting global scope whenever possible.
* Since I use subdirs for my components, it also flattens the structure making
* _componentStore[className] possible.
* Creds for the react_ujs.js file to the people from react-rails (https://github.com/reactjs/react-rails)
*/
var path = require('path');
cat db/seeds/countries.json | ruby -rubygems -e 'require "json";a=JSON.pretty_generate JSON.parse gets;File.open("db/seeds/countries.json", "w"){|f| f << a}'
@dmshvetsov
dmshvetsov / seed.rb
Created August 23, 2013 09:58
example of DRY seed.rb
country_list = [
[ "Germany", 81831000 ],
[ "France", 65447374 ],
[ "Belgium", 10839905 ],
[ "Netherlands", 16680000 ]
]
country_list.each do |name, population|
Country.create( name: name, population: population )
end
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
//code for displaying results
//document.getElementById('show-lat-lon').innerHTML='<p>' + latitude + ' ' + longitude + '</p>';
});
} else {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var coord = new google.maps.LatLng(latitude,longitude);
geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': coord}, function(results, status) {
for (var i = 0; i < results[4].address_components.length; i++) {