This is the source code of one of my blog post. To read the full blog post please click here.
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 java.lang.reflect.Constructor; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.LinkedList; | |
import java.util.List; | |
public final class NaiveBuilder { | |
public static <T> T build(Class<T> aClass) throws IllegalAccessException, InvocationTargetException, InstantiationException { | |
Constructor<?> firstConstructor = aClass.getConstructors()[0]; | |
if (hasDependencies(firstConstructor)) { | |
Object[] dependencies = resolve(firstConstructor); |
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
module['exports'] = function bot (hook) { | |
var request = require('request'); | |
var TOKEN = hook.env.bot_scheduler_token; | |
var ENDPOINT = 'https://api.telegram.org/bot' + TOKEN; | |
console.log(hook.params); | |
// generic handler to log api call responses | |
var handler = function (err, httpResponse, body) { | |
var response = JSON.stringify({ |
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
<?php | |
require("./vendor/autoload.php"); | |
define('BOT_TOKEN', 'token'); | |
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/'); | |
function apiRequestWebhook($method, $parameters) { | |
if (!is_string($method)) { | |
error_log("Method name must be a string\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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.network "private_network", ip: "192.168.33.10" | |
config.vm.provider "virtualbox" do |vb| | |
vb.memory = "1024" | |
end | |
config.vm.provision "docker" do |d| |
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
public class OISC { | |
int programCounter, a, b, c; | |
void run(int[] memory) { | |
while (programCounter >= 0) { | |
/*System.out.printf("-----\n"); | |
for (int i = 0; i < memory.length; i++) { | |
System.out.printf("%d\t|%d\n", i, memory[i]); | |
} | |
System.out.printf("-----\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
import java.util.Arrays; | |
/** | |
* Stooge sort is a recursive sorting algorithm with a time complexity of | |
* O(n^(log 3 / log 1.5) ) = O(n^(2.7095...)). The running time of the | |
* algorithm is thus slower compared to efficient sorting algorithms, such as | |
* Merge sort, and is even slower than Bubble sort, a canonical example of a | |
* fairly inefficient and simple sort. | |
* | |
* The algorithm is defined as follows: | |
* |
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 java.util.Arrays; | |
/** | |
* quickselect is a selection algorithm to find the kth smallest element in an | |
* unordered list. Like quicksort, it is efficient in practice and has good | |
* average-case performance, but has poor worst-case performance. Quickselect | |
* and variants is the selection algorithm most often used in efficient | |
* real-world implementations. | |
* | |
* Quickselect uses the same overall approach as quicksort, choosing one |
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
<?php | |
// Original PHP code by Chirp Internet: www.chirp.com.au | |
// Please acknowledge use of this code by including this header. | |
function myTruncate($string, $limit, $break=".", $pad="...") { | |
// return with no change if string is shorter than $limit | |
if(strlen($string) <= $limit) | |
return $string; | |
// is $break present between $limit and the end of the string? |
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
<?php | |
/****************** | |
*@email - Email address to show gravatar for | |
*@size - size of gravatar | |
*@default - URL of default gravatar to use | |
*@rating - rating of Gravatar(G, PG, R, X) | |
*/ | |
function show_gravatar($email, $size, $default, $rating) | |
{ |
NewerOlder