Skip to content

Instantly share code, notes, and snippets.

View luthfianto's full-sized avatar

Rizky Luthfianto luthfianto

View GitHub Profile
@luthfianto
luthfianto / INTERSECTWITHSKIPS.py
Created March 16, 2014 17:37
A bad implementation of intersection via skip pointers from Chapter 2 of "Introduction to Information Retrieval"
from math import sqrt, ceil
class SkipList:
def __init__(self, list, i=0):
self.list=list
self.len=len(self.list)
self.interval=ceil(sqrt(self.len))
self.i=i
def next(self):
@luthfianto
luthfianto / soundex.js
Last active August 18, 2018 21:50
An implementation of Soundex algorithm in JavaScript. (Introduction to Information Retrieval)
var isAlpha = function(s) { return /^[a-zA-Z]+$/.test(s) }
var soundex = function(s) {
if(s==='')
return '0000'
const
head = s[0].toLowerCase(),
tail = s.substr(1).toLowerCase()
@luthfianto
luthfianto / soundex.jl
Created March 22, 2014 14:07
A bad implementation of Soundex in Julia. Not sure if its working though
function soundex(s::String)
const head = lowercase(s[1])
const tail = lowercase(s[2:end])
const dict= [ "a"=>"", "e"=>"", "i"=>"", "o"=>"", "u"=>"", "y"=>"", "h"=>"", "w"=>"", "b"=>"1", "f"=>"1", "p"=>"1", "v"=>"1", "c"=>"2", "g"=>"2", "j"=>"2", "k"=>"2", "q"=>"2", "s"=>"2", "x"=>"2", "z"=>"2", "d"=>"3", "t"=>"3", "l"=>"4", "m"=>"5", "n"=>"5", "r"=>"6"]
const t=split(tail,"")
const t1=map(x->dict[x],t)
output=ASCIIString[]
# 1. Delete all existing rules
iptables -F
# 2. Set default chain policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# 4. Allow ALL incoming SSH
iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
@luthfianto
luthfianto / dda.js
Created September 29, 2014 12:48
Digital Differential Analyzer in JavaScript
function dda(x0, y0, x1, y1)
{
const dx = x1 - x0,
dy = y1 - y0,
s = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy),
xi = dx * 1.0 / s,
yi = dy * 1.0 / s
var x = x0,
y = y0,
@luthfianto
luthfianto / iptables
Created October 4, 2014 10:34
Some simple iptables rule
iptables -F
#Prevent DDOS, kudos to Digital Ocean
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
@luthfianto
luthfianto / saving_mechanize_cookie.rb
Last active August 29, 2015 14:08
saving mechanize cookie
@luthfianto
luthfianto / mount_lenovo_a706.sh
Created November 12, 2014 11:04
Mount Lenovo A706 internal SD
mount -o umask=0000,dmask=0000 -t vfat /dev/block/mmcblk0p20 /storage/sdcard1
@luthfianto
luthfianto / Dockerfile
Last active August 29, 2015 14:10
tes dockerfile
FROM sequenceiq/spark:1.1.0
MAINTAINER Rizky m.rizky.l@mail.ugm.ac.id
RUN git clone git://gist.github.com/2a229e3a7cc88cc442fe.git
#RUN git clone git://bitbucket.org/rilut/tk.git
CMD ["/etc/bootstrap.sh", "-d"]