This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def roman_to_integer(s: str) -> int: | |
T = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000} | |
return functools.reduce( | |
lambda val, i: val + (-T[s[i]] if T[s[i]] < T[s[i+1]] else T[s[i]]), | |
reversed(range(len(s)-1)), T[s[-1]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('tr.memberships__table-row') | |
.filter( function () { return $(this).find('td.memberships__td-user-status--active').length }) | |
.map( function () { return $(this).find('td.memberships__td-user').get(0).title }) | |
.get() | |
.sort() | |
.join("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn nodes-to-bequeath [parent] | |
(xml-> (zipper/xml-zip parent) | |
zipper/children | |
#(if (get-in % [:attrs ::pm/inherit]) % nil))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns scratch.scratch | |
(:gen-class)) | |
(defn effect? [[k f]] | |
(= \! (last (name k)))) | |
(defn if? [[k f]] | |
(= :if k)) | |
(defn step [model fsm] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# | |
# nit-parallel [cosmos-running-instances args ...] -- [parallel args ...] | |
# | |
# e.g. | |
# | |
# ### No piped input: run command on all hosts | |
# nit-parallel -e test pm-nitro-test-1 -- hostname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ function map () { while read -r VAR; do eval "$@"; done } | |
$ seq 5 | map echo '{{{$VAR}}}' | |
{{{1}}} | |
{{{2}}} | |
{{{3}}} | |
{{{4}}} | |
{{{5}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; use warnings; | |
use XML::LibXML; | |
use XML::LibXML::XPathContext; | |
my $xml = <<'__EOI__'; | |
<par xmlns:bar="www.bar.com"><bar:foo/></par> | |
__EOI__ | |
my $parser = XML::LibXML->new(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#### | |
# Split MySQL dump SQL file into one file per table | |
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump | |
# from https://gist.github.com/jasny/1608062 | |
#### | |
if [ $# -lt 1 ] ; then | |
echo "USAGE $0 DUMP_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use File::Spec; | |
my $in = 'in'; | |
my $out = 'out'; | |
sub process { | |
my ($in, $out, $callback) = @_; | |
opendir (my $DIR, $in) or die "Failed to open dir $in: $!"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boot.user=> (defn and->> [f value] (doto value f)) | |
#'boot.user/and->> | |
boot.user=> (defn and-> [value f] (doto value f)) | |
#'boot.user/and-> | |
;; use the appropriate and->(>) form for your threading macro | |
boot.user=> (-> 1 (and-> println)) | |
1 | |
1 |
NewerOlder