Given an input.txt
that represents a linked list a -> b -> c -> d -> e
as a series of nodes with next
pointers:
a>b
b>c
c>d
d>e
Reverse the linked list such that the output reads:
object Foo { | |
var initialized = 0 | |
// This only happens once regardless of how many times Foo.fetch() is called | |
initialized = initialized + 1 | |
def fetch(): Integer = initialized | |
} | |
class Foo { |
while (current != null) { | |
next = current->next; | |
current->next = prev; | |
prev = current; | |
current = next; | |
} | |
head = prev; |
Given an input.txt
that represents a linked list a -> b -> c -> d -> e
as a series of nodes with next
pointers:
a>b
b>c
c>d
d>e
Reverse the linked list such that the output reads:
#!/usr/bin/env bash | |
# Where input.txt is: | |
# a>b | |
# b>c | |
# c>d | |
# d>e | |
paste -d '>' <(< input.txt | cut -d'>' -f2 | tac) <(< input.txt | cut -d'>' -f1 | tac) |
#!/usr/bin/env bash | |
seq 1 100 | \ | |
xargs -Ix -n1 echo "x + ((x % 3 == 0) + ((x % 5) == 0) * 2) * 1000" | \ | |
bc | \ | |
xargs -n1 printf "%04d\n" | \ | |
sed 's/^1.*/Fizz/' | \ | |
sed 's/^2.*/Buzz/' | \ | |
sed 's/^3.*/FizzBuzz/' | \ | |
sed 's/^0*//' |
def convert(char): | |
return { | |
'M': 1000, | |
'D': 500, | |
'C': 100, | |
'L': 50, | |
'X': 10, | |
'V': 5, | |
'I': 1 | |
}.get(char) |
// This doodad converts absolute paths like "/assets/thing.jpg" into relative ones like "assets/thing.jpg" | |
NSString * (^fixPrefix)(NSString *, NSString *) = ^NSString *(NSString * input, NSString *prefix) { | |
NSString *needle = [[@"/" stringByAppendingString:prefix] stringByAppendingString:@"/"]; | |
NSString *replacement = [prefix stringByAppendingString:@"/"]; | |
input = [input stringByReplacingOccurrencesOfString:[@"'" stringByAppendingString:needle] withString:[@"'" stringByAppendingString:replacement]]; | |
input = [input stringByReplacingOccurrencesOfString:[@"\"" stringByAppendingString:needle] withString:[@"\"" stringByAppendingString:replacement]]; | |
input = [input stringByReplacingOccurrencesOfString:[@"(" stringByAppendingString:needle] withString:[@"(" stringByAppendingString:replacement]]; | |
return input; |
// There is no String.substr on Salesforce. This uses String.substring instead. | |
// substring's arguments are different, so this just converts substr args to | |
// their substring equivalents. | |
function substrShim (str, start, len) { | |
if (len <= 0) | |
return ''; | |
if (start < 0) | |
start = str.length + start; |
Platform.Load('Core', '1.0'); | |
function moo (foo, bar) {}; | |
Write(moo.length); // You'll get a .NET error if you do this, weirdly enough. |
define('foo', function () { | |
function Foo () { | |
Write('Hello World'); | |
}; | |
return Foo; | |
}) | |
require(['foo'], function (Foo) { | |
// Foo is undefined on Salesforce |