Skip to content

Instantly share code, notes, and snippets.

Dave Vasilevsky vasi

Block or report user

Report or block vasi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vasi
vasi / fib.rb
Created Jan 28, 2018
Dumbest fibonacci ever
View fib.rb
#!/usr/bin/env ruby
def fib0(a)
0.upto(a.size-1) { |i| a[i] += 1 }
end
def fib1(a)
fib0(a)
end
@vasi
vasi / Results
Created May 25, 2017
Mac browser market share in last year, from Wikipedia
View Results
Safari 47.5
Chrome 40.6
Firefox 8.9
AppleMail 2.6
Other 0.3
PhantomJS 0.0
Camino 0.0
WebKit Nightly 0.0
@vasi
vasi / brewfoster
Created May 17, 2017
Manage a clean homebrew installation
View brewfoster
#!/usr/bin/env ruby
require 'pathname'
require 'set'
require 'pp'
def dependencies
deps = {}
IO.popen(['brew', 'deps', '--installed']) do |f|
f.each do |line|
md = /^([^:]+):\s*(.*)$/.match(line) or raise "Can't parse dependencies"
@vasi
vasi / dry_run.php
Created Mar 30, 2017
Drupal migrate dry run
View dry_run.php
<?php
use Drupal\migrate_plus\Event\MigrateEvents as MigratePlusEvents;
use Drupal\migrate_plus\Event\MigratePrepareRowEvent;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
function dry_run_migration($migration_id) {
// Get the migration source.
$migrationManager = \Drupal::service('plugin.manager.config_entity_migration');
$migration = $migrationManager->createInstance($migration_id);
@vasi
vasi / uuid.php
Last active Jul 17, 2019
Modify Drupal's config UUIDs to match a config dir
View uuid.php
<?php
use Symfony\Component\Yaml\Yaml;
global $config_directories;
$config_name = drush_shift();
if (!isset($config_directories[$config_name])) {
print "No such config directory $config_name\n";
exit;
}
@vasi
vasi / toggl2rm.rb
Created Dec 9, 2016
Import time logs from Toggl to Redmine
View toggl2rm.rb
#!/usr/bin/ruby
require 'date'
require 'json'
require 'net/http'
require 'openssl'
require 'optparse'
require 'ostruct'
require 'pp'
def req(url, method = :Get)
@vasi
vasi / mdns.pl
Created Oct 3, 2016
mDNS in pure Perl, no extra modules needed
View mdns.pl
#!/usr/bin/perl
use warnings;
use strict;
use IO::Select;
use IO::Socket::INET;
# Build an mDNS query.
sub build_query {
my $domain = shift;
View test.rs
use std::rc::Rc;
use std::cell::RefCell;
use std::ops::DerefMut;
struct A<'a> {
pub v: Vec<Rc<RefCell<FnMut() + 'a>>>,
}
impl<'a> A<'a> {
pub fn add3<F: FnMut() + 'a>(&mut self, f: F) {
let r = Rc::new(RefCell::new(f));
View mh.php
<?php
// Helper for executing migrations in D8, without migrate_tools.
$args = drush_get_arguments();
array_splice($args, 0, 2);
$cmd = array_shift($args);
switch ($cmd) {
case 'mi':
View migrate.migration.shows.yml
id: shows
migration_tags: { }
label: 'TV shows'
source:
plugin: json_source
path: 'http://api.tvmaze.com/search/shows?q=family'
identifier: id
identifierDepth: 1
headers: { }
fields: { }
You can’t perform that action at this time.