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 / Volleyball.cs
Created February 16, 2015 13:06
HackerRank Volleyball Match Solution
using System;
namespace Solution
{
// Algorithm discussion at https://www.hackerrank.com/challenges/volleyball-match/editorial referenced
// (Not enough time to develop algorithm!)
class Solution
{
public const int Modular = 1000000007;
public static string BytesToString(long byteSize)
{
const string format = "{0} {1}";
const int orderBase = 1024;
var units = new[] {"B", "KB", "MB", "GB", "TB", "PB", "EB"};
if (byteSize == 0)
return "0 B";
var order = Convert.ToInt32(Math.Floor(Math.Log(byteSize, orderBase)));
var rescaledSize = Math.Round(byteSize/Math.Pow(orderBase, order), 1);
@lawliet89
lawliet89 / palindrome.cpp
Created November 12, 2012 23:22
The Next Palindrome (SPOJ)
// https://www.spoj.pl/problems/PALIN/
// Concept: http://www.algorithmist.com/index.php/SPOJ_PALIN
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool lessThan(vector<int> obj1, vector<int> obj2);
void helper(const vector<int> &input, vector<int> &output, int stage=0);
@lawliet89
lawliet89 / 3m.cpp
Created November 13, 2012 00:11
Mean, Median, Mode
// Mean medium and mode
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <map>
using namespace std;
// This is a variant of merge sort that does mode counts and sums all the items.
template <typename InputIterator, typename OutputIterator, typename ValueType, typename SumType> void mergesort(InputIterator start, InputIterator end, OutputIterator output, SumType &sum, map<ValueType, int> &mode){
@lawliet89
lawliet89 / quicksort.cpp
Last active October 12, 2015 23:58
C++ Generic Quicksort
// Quicksort - see makefile for compiling options with G++.
// Will not compile in VS2012 due to initialiser syntax in main() for std::vector
#include <iostream>
#include <vector>
#include <algorithm> // Required
#include <iterator> //Required
#include <stdlib.h> // Required
#include <time.h> // Required
// Function Prototypes
@lawliet89
lawliet89 / concat.py
Created May 10, 2013 12:41
Python concatenate list of string
def list_to_string(lst, delim=''):
"""Concatenate a list of strings to one single string. Specify a delimiter to append to end of each fragment"""
return reduce((lambda a, b: a + delim + b), lst)
@lawliet89
lawliet89 / Strip.py
Last active December 17, 2015 04:58
Strip list/dictionaries of empty items recursively
def strip(content):
"""Strip Empty Variables"""
if (type(content) is list):
return strip_list(content)
elif (type(content) is dict):
return strip_dictionary(content)
elif (content):
return content
else:
return None
@lawliet89
lawliet89 / gist:5728344
Created June 7, 2013 10:14
Git Regular Expression search (grep) for missing trailing newline
git grep -I -E "[^\n]\'"
@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;