Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
if [ `id -u` != "0" ]; then
echo "Error: Must run as root"
exit 1
fi
VERSION=${1:-1.1.0}
URL_BASE="http://storage.googleapis.com/downloads.webmproject.org/releases/webp/"
@adi-li
adi-li / Combinator.swift
Created March 27, 2021 07:11
Iterating all possible combinations of r elements in a given array of objects in Swift
class Combinator<Object>: IteratorProtocol {
typealias Element = [Object]
var objects: [Object]
var numberOfSelection: Int
private var currentIndexes: [Int]
private var done = false
func next() -> [Object]? {
guard !currentIndexes.isEmpty else { return nil }
@adi-li
adi-li / meteorsis-api.js
Last active August 6, 2019 10:08
Unofficial Meteorsis API for node.js (https://www.meteorsis.com)
const rp = require('request-promise-native');
const https = require('https');
const querystring = require('querystring');
const iconv = require('iconv-lite');
const baseUrl = 'https://www.meteorsis.com/misweb/';
const MeteorsisApiErrorCodeMap = {
@adi-li
adi-li / example.js
Last active December 22, 2018 16:50 — forked from faisalman/example.js
7-bit GSM 03.38 <-> Unicode Map in JS
// Unicode to 7-bit GSM
const write = 'Hello, Faisalman!';
const msgSubmit = Array.from(write)
.map(char => Unicode2GSM[char].toString(16))
.join(' ');
console.log(msgSubmit); // "48 65 6C 6C 6F 2C 20 46 61 69 73 61 6C 6D 61 6E 21"
// 7-bit GSM to Unicode
const read = "48 65 6C 6C 6F 2C 20 46 61 69 73 61 6C 6D 61 6E 21";
const msgReceived = read.split(' ')
@adi-li
adi-li / montyhall.swift
Created November 2, 2017 18:00
Monty Hall Problem - Weird Probability
import Foundation
//: Playground - noun: a place where people can play
import UIKit
func random(lessThan aNumber: Int) -> Int {
return Int(arc4random_uniform(UInt32(aNumber)))
}
@adi-li
adi-li / data.json
Created September 8, 2016 11:21
Parse | Example data for adding a user to a role by REST API
# PUT it to `classes/_Role/roleID`
{
"users": {
"__op": "AddRelation",
"objects": [
{
"__type": "Pointer",
"className": "_User",
"objectId": "objectId"
@adi-li
adi-li / generate-self-signed-certificate.sh
Last active August 22, 2016 07:29
Generate self-signed certificate and key in bash.
#!/bin/bash
generate-self-signed-certificate () {
if [[ $1 ]]; then
openssl req -nodes -x509 -newkey rsa:2048 -keyout $1.key -out $1.crt -days 3650
return 0
fi
echo -e "\033[0;31mPlease provide the name of the key.\033[0m" 1>&2
return 1
}
@adi-li
adi-li / extend.py
Last active August 11, 2016 03:35
Try to extend a class by adding / overriding original method in Python
class Foo(object):
def bar(self):
return 'bar'
def new_bar(self, super_method):
if super_method is not None:
return ', '.join([super_method(), 'new_bar'])
return 'new_bar'
@adi-li
adi-li / AllowInvalidCertificate.m
Created July 11, 2016 15:00
Parse allow invalid certificate in iOS
// ParseClientConfiguration.h
@protocol ParseMutableClientConfiguration <NSObject>
@property (nonatomic, assign) BOOL allowInvalidCertificate;
@end
@interface ParseClientConfiguration : NSObject <NSCopying>
@property (nonatomic, assign, readonly) BOOL allowInvalidCertificate;
@end
@adi-li
adi-li / can_i_join_snaptee.py
Last active June 27, 2016 17:33
Can I join Snaptee? | Snaptee is recruiting developer 📱💻 https://snaptee.co/jobs/#software-eng | Try to finish the below game to win the opportunity.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import readline
class Developer(object):
def __init__(self, name, email, skills):
self.name = name
self.email = email