Skip to content

Instantly share code, notes, and snippets.

View dmshvetsov's full-sized avatar
🪄

Dmitry Shvetsov dmshvetsov

🪄
View GitHub Profile
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
@dmshvetsov
dmshvetsov / seed.rb
Last active June 1, 2019 15:29
How to seed your database with JSON/YAML. Source http://snippets.aktagon.com
json = ActiveSupport::JSON.decode(File.read('db/seeds/countries.json'))
json.each do |a|
Country.create!(a['country'], without_protection: true)
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++) {
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
table {
border-collapse: collapse;
@dmshvetsov
dmshvetsov / mac_extend_PATH.sh
Created November 15, 2013 14:06
To set /usr/local/sbin/sampleapp to $PATH, enter:
sudo -s 'echo "/usr/local/sbin/sampleapp" > /etc/paths.d/sampleapp'
@dmshvetsov
dmshvetsov / from1251toUTF8.sh
Created January 9, 2014 00:30
character set conversion (one line shell command)
iconv -f WINDOWS-1251 -t UTF-8 <upper_form.php >upper_form_utf.php
@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