Skip to content

Instantly share code, notes, and snippets.

View unnikked's full-sized avatar
🏠
Working from home

Nicola Malizia unnikked

🏠
Working from home
View GitHub Profile
@unnikked
unnikked / README.md
Last active February 19, 2024 02:58
How to host your Telegram bot on Google App Script

Telegram Bot on Google App Script

This is the source code of one of my blog post. To read the full blog post please click here.

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);
@unnikked
unnikked / botscheduler.js
Last active July 24, 2021 00:29
Bot scheduler for Telegram - to use with IFTTT - please check https://unnikked.ga/build-telegram-bot-hook-io/ for instructions
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({
@unnikked
unnikked / index.php
Created January 5, 2016 22:02
InlineDuckBot
<?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");
@unnikked
unnikked / Vagrantfile
Last active March 17, 2016 08:56
Provision Huginn on a Vagrant Box via Docker
# -*- 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|
@unnikked
unnikked / OISC.java
Last active November 10, 2015 17:38
OISC Implementation in Java
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");*/
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:
*
@unnikked
unnikked / QuickSelect.java
Created July 4, 2015 15:40
A basic implementation of quickselect algorithm in Java. Intentionally unused generics.
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
@unnikked
unnikked / truncate_text.php
Created March 31, 2015 16:01
This function will truncate strings only at word breaks which can be used to show a teaser for complete article without breaking words.
<?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?
@unnikked
unnikked / gravatar_show.php
Created March 31, 2015 16:00
Show gravatar from user email
<?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)
{