Skip to content

Instantly share code, notes, and snippets.

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 }
def fib1(a)
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 / 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 / dry_run.php
Created Mar 30, 2017
Drupal migrate dry run
View dry_run.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 / uuid.php
Last active Nov 2, 2020
Modify Drupal's config UUIDs to match a config dir
View uuid.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";
vasi / toggl2rm.rb
Created Dec 9, 2016
Import time logs from Toggl to Redmine
View toggl2rm.rb
require 'date'
require 'json'
require 'net/http'
require 'openssl'
require 'optparse'
require 'ostruct'
require 'pp'
def req(url, method = :Get)
vasi /
Created Oct 3, 2016
mDNS in pure Perl, no extra modules needed
use warnings;
use strict;
use IO::Select;
use IO::Socket::INET;
# Build an mDNS query.
sub build_query {
my $domain = shift;
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
// 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'
plugin: json_source
path: ''
identifier: id
identifierDepth: 1
headers: { }
fields: { }