Skip to content

Instantly share code, notes, and snippets.

View qti3e's full-sized avatar
😃

Parsa qti3e

😃
View GitHub Profile
@qti3e
qti3e / break.js
Created March 27, 2018 10:34
Why break in a switch statement is important?
const o = {
i: 0,
get x() {
return this.i++;
}
};
switch (o.x) {
case 0:
console.log("a");
case 1:
@qti3e
qti3e / lcs.ts
Created March 24, 2018 23:58
Longest common substring
function Int2DArray(a: number, b: number) {
const data = new Int32Array(a * b);
return {
set(i: number, j: number, v: number) {
const index = j * a + i;
data[index] = v;
},
get(i: number, j: number) {
const index = j * a + i;
return data[index];
@qti3e
qti3e / imshow_rgba.patch
Last active March 6, 2018 19:43
Support RGBA in imshow
commit f37df59507f77cd9e7cad33c27b6c63dd7aae0e5
Author: Parsa Ghadimi <qti3eqti3e@gmail.com>
Date: Tue Mar 6 22:15:36 2018 +0330
[Fix #196] Support RGB in imshow
diff --git a/src/im.ts b/src/im.ts
index adbd34e..26f0c55 100644
--- a/src/im.ts
+++ b/src/im.ts
@qti3e
qti3e / redis.php
Created March 2, 2018 19:39
Simple Redis Client to understand it's protocol
<?php
/**
* Class myRedisException
*/
class myRedisException extends Exception{
/**
* @var null|string
*/
private $command = '';
/**
@qti3e
qti3e / index.php
Created March 2, 2018 19:33
A simple template engine in PHP
<?php
// 2015/07 :)
/**
* The core class of Template Engine
* Class templateEngine
*/
class templateEngine{
/**
* @type array
*/
@qti3e
qti3e / example.php
Created March 2, 2018 19:32
Simple NoSQL entirely in PHP
<?php
$time1 = microtime(true);
include "lib.php";
try{
$db = new array_db("db1");
}catch(Exception $e){
echo $e->getMessage();
}
$db->install([
"users" => [
@qti3e
qti3e / redis-indexer.flow.js
Last active February 24, 2018 00:53
Show-case: Redis as a simple indexing backend in Node.js
// @flow
import Redis from 'redis';
import bluebird from 'bluebird';
import type {RedisClient} from 'redis';
import uuid from 'uuid/v4';
import md5 from 'md5';
bluebird.promisifyAll(Redis.RedisClient.prototype);
const SearchClient: RedisClient = Redis.createClient({
db: 2
});
@qti3e
qti3e / Perceptron.js
Last active January 31, 2018 23:06
Simple Perceptron in Propel
import { Params, T } from "propel"
let params = new Params()
let trainingData = [
[[0, 0, 1], 0],
[[0, 1, 1], 1],
[[1, 0, 1], 1],
[[1, 1, 1], 1]
]
let unit_step = x => x < 0 ? 0 : 1
let w = params.randn("W", [3])
@qti3e
qti3e / withWindowDimensions.js
Created January 28, 2018 12:11
withWindowDimensions React.js HOC
import React, {Component} from 'react'
import hoistNonReactStatic from 'hoist-non-react-statics'
export default function(WrappedComponent){
class withWindowDimensions extends Component{
constructor(props){
super(props)
this.updateDimensions = this.updateDimensions.bind(this)
}
@qti3e
qti3e / iran-phone-validation.js
Last active December 19, 2017 20:57
Validate and normalize Iran phone numbers, supports for converting Persian digits
let persian = {'۰': 0, '۱': 1, '۲': 2, '۳': 3, '۴': 4, '۵': 5, '۶': 6, '۷': 7, '۸': 8 , '۹': 9}
function validateAndNormalizePhone(phone){
if(!phone || typeof phone !== 'string')
return false
phone = phone.replace(/ /g, '')
let tmp = ''
for(let i = 0;i < phone.length;i++){
let letter = phone[i]