Skip to content

Instantly share code, notes, and snippets.

Ben Ng ben-ng

Block or report user

Report or block ben-ng

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
@ben-ng
ben-ng / rev.c
Created Mar 4, 2019
Reverse a linked list in C
View rev.c
while (current != null) {
next = current->next;
current->next = prev;
prev = current;
current = next;
}
head = prev;
@ben-ng
ben-ng / problem-statement.md
Created Mar 4, 2019
Reverse a linked list in Bash
View problem-statement.md

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:

@ben-ng
ben-ng / reverse-linked-list.sh
Created Mar 4, 2019
Solution for reversing a linked list in bash
View reverse-linked-list.sh
#!/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)
@ben-ng
ben-ng / fizzbuzz.sh
Created Mar 4, 2019
FizzBuzz solved with data-flow programming in Bash.
View fizzbuzz.sh
#!/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*//'
@ben-ng
ben-ng / substr.js
Last active Mar 29, 2017
substr shim
View substr.js
// 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;
@ben-ng
ben-ng / a-repro.js
Last active Mar 28, 2017
AMD silently misbehaving on Salesforce Marketing Cloud
View a-repro.js
define('foo', function () {
function Foo () {
Write('Hello World');
};
return Foo;
})
require(['foo'], function (Foo) {
// Foo is undefined on Salesforce
@ben-ng
ben-ng / a-repro.js
Last active Mar 29, 2017
Salesforce Marketing Cloud Function.length bug
View a-repro.js
Platform.Load('Core', '1.0');
function moo (foo, bar) {};
Write(moo.length); // You'll get a .NET error if you do this, weirdly enough.
@ben-ng
ben-ng / a-repro.js
Created Mar 24, 2017
Salesforce Marketing Cloud constructor-from-closure bug
View a-repro.js
function newEnv () {
function Foo () {
Write('Hello World');
};
var f = {
Foo: Foo
}
return f;
@ben-ng
ben-ng / a-repro.js
Last active Mar 24, 2017
Salesforce Marketing Cloud closure scope bug
View a-repro.js
function foo() {
function boom() {
Write('Boom');
};
function bar () {
function baz() {
boom(); // Fails here, "boom" can't be found
};
@ben-ng
ben-ng / try-1.txt
Last active Dec 5, 2016
Swift build failure logs
View try-1.txt
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-31-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
100 packages can be updated.
47 updates are security updates.
You can’t perform that action at this time.