Skip to content

Instantly share code, notes, and snippets.

View lawliet89's full-sized avatar
πŸ§‘β€πŸ€β€πŸ§‘
He/him

Yong Wen Chua lawliet89

πŸ§‘β€πŸ€β€πŸ§‘
He/him
View GitHub Profile
@lawliet89
lawliet89 / gist:9439285
Created March 8, 2014 21:38
std::function declaration of the std::min function
#include <functional>
#include <iostream>
#include <algorithm>
int main() {
std::function<const int &(const int &, const int &)> func =
(const int & (*)(const int &, const int &)) & std::min;
std::cout << func(1, 2);
}
@lawliet89
lawliet89 / stack-sort.cpp
Created January 27, 2014 21:52
Sort numbers using only two stacks
#include <stack>
#include <iostream>
#include <vector> // for lazy man initialisation
using namespace std;
/*
Using two stacks ONLY, sort a stack with biggest item on top
*/
@lawliet89
lawliet89 / hanoi.cpp
Last active January 4, 2016 17:59
Rudimentary Tower of Hanoi Solver
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
void moveDisks(int number, stack<int> &origin, stack<int> &destination, stack<int> &buffer);
void moveTop(stack<int> &origin, stack<int> &destination);
int main() {
@lawliet89
lawliet89 / binary-search-tree.cpp
Last active June 3, 2020 03:48
C++ Generic Binary Search Tree
#include <iostream>
#include <new>
#include <cassert>
#define NUMBER 9
template <typename T> class Node {
public:
Node<T> *parent, *left, *right;
@lawliet89
lawliet89 / README.txt
Last active December 29, 2015 08:39
Facebook Secret Decoder Programming Exercise
Question 1 / 1 (secret decoder)
Your task is to decode messages that were encoded with substitution ciphers. In a substitution cipher, all occurrences of a character are replaced by a different character. For example, in a cipher that replaces "a" with "d" and "b" with "e", the message "abb" is encoded as "dee".
The exact character mappings that are used in the substitution ciphers will not be known to you. However, the dictionary of words that were used will be given. You will be given multiple encoded messages to decode (one per line) and they may use different substitution ciphers. The same substitution cipher is used on all of the words in a particular message.
For each scrambled message in the input, your program should output a line with the input line, followed by the string " = " (without the quotes), followed by the decoded message.
NOTE: All inputs are from stdin and output to stdout. The input will be exactly like how it's given in the problem and
your output should exactly match the given exam
@lawliet89
lawliet89 / gist:6722154
Created September 26, 2013 23:39
Cross browser greyscale
img {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter: grayscale(100%);
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale");
filter: gray; /* IE 6-9 */
}
@lawliet89
lawliet89 / gist:6654953
Last active January 30, 2016 01:52
jQuery Contained Sticky Scroll
/*!
* Contained Sticky Scroll
* Adapted from Matt Ward's code
* http://blog.echoenduring.com/2010/11/15/freebie-contained-sticky-scroll-jquery-plugin/
*/
(function($){
$.fn.containedStickyScroll = function(options) {
var defaults = {
offsetTop: 0,
topClass: '',
@lawliet89
lawliet89 / menu.less
Last active December 21, 2015 11:39
CSS Navigation Menu
@charset "UTF-8";
ul.navigation-menu { // Level 1
.transition() {
-webkit-transition: all 300ms ease;
-moz-transition: all 300ms ease;
-ms-transition: all 300ms ease;
-o-transition: all 300ms ease;
transition: all 300ms ease;
}
@text-color: #ffffff;
@lawliet89
lawliet89 / gist:5899943
Created July 1, 2013 10:55
Git grep for trailing whitespace
git grep -I -E '^.+[ ]+$'
@lawliet89
lawliet89 / gist:5728344
Created June 7, 2013 10:14
Git Regular Expression search (grep) for missing trailing newline
git grep -I -E "[^\n]\'"