Skip to content

Instantly share code, notes, and snippets.

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

Aamir khan iamaamir

🏠
Working from home
  • Postman
  • New Delhi
  • 12:54 (UTC +05:30)
  • LinkedIn in/itsaamir
View GitHub Profile
@iamaamir
iamaamir / stringCompress.js
Created February 3, 2020 06:31
simplest string compression in js
// https://stackoverflow.com/questions/4570333/string-compression-in-javascript
function en(c){var x='charCodeAt',b,e={},f=c.split(""),d=[],a=f[0],g=256;for(b=1;b<f.length;b++)c=f[b],null!=e[a+c]?a+=c:(d.push(1<a.length?e[a]:a[x](0)),e[a+c]=g,g++,a=c);d.push(1<a.length?e[a]:a[x](0));for(b=0;b<d.length;b++)d[b]=String.fromCharCode(d[b]);return d.join("")}
function de(b){var a,e={},d=b.split(""),c=f=d[0],g=[c],h=o=256;for(b=1;b<d.length;b++)a=d[b].charCodeAt(0),a=h>a?d[b]:e[a]?e[a]:f+c,g.push(a),c=a.charAt(0),e[o]=f+c,o++,f=a;return g.join("")}
var compressed=en("http://www.ScriptCompress.com - Simple Packer/Minify/Compress JavaScript Minify, Fixify & Prettify 75 JS Obfuscators In 1 App 25 JS Compressors (Gzip, Bzip, LZMA, etc) PHP, HTML & JS Packers In 1 App PHP Source Code Packers Text Packer HTML Packer or v2 or v3 or LZW Twitter Compress or More Words DNA & Base64 Packer (freq tool) or v2 JS JavaScript Code Golfer Encode Between Quotes Decode Almost Anything Password Protect Scripts HTML Minifier v2 or En
// Sum Numbers over an array
const sum = array => array.reduce((acum, number) => {
return acum + number;
}, 0);
console.log('01', { sum: sum([ 1, 5, 9 ]) });
// Sum Numbers multiplied by a factor
const sumProduct = array => array.reduce((acum, pair) => {
const [ number, factor ] = pair;
import { useEffect, useState } from 'react';
// this func do not cover all the cases
function debounce(func, wait = 100) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => {
func.apply(this, args);
}, wait);
1. Incognito by David Eagleman
2. How Smart Machines Think by Sean Gerrish
3. The Hundred-Page Machine Learning Book by Andriy Burkov
4. Python Machine Learning (2nd Edition) by Sebastian Rasckha & Vahid Mirjalili
5. Deep Learning by Andrew W. Trask
6. Bayesian Methods For Hackers by Cameron Davidson - Pilon
7. Doing Data Science by Cathy O'Neil & Rachel Schutt
8. Reinforcement Learning by Richard S. Sutton & Andrew G. Barto
9. The Book of Why by Judea Pearl & Dana Mackenzie
10. Quantum Machine Learning by Peter Wittek
@iamaamir
iamaamir / helpers.js
Last active May 14, 2019 16:46
js helper functions
// Date object to unix timestamp
function unix(date) {
return Math.round(date.getTime() / 1000);
}
// replace all from string
String.prototype.replaceAll = function(rgx, replacement) {
var self = this;
return self.replace(new RegExp(rgx, "g"), replacement);
};
@iamaamir
iamaamir / getFakeProfiles.js
Last active February 14, 2019 09:29
get some fake random user profiles
function getFakeProfiles(){
return fetch('https://randomuser.me/api')
.then(res => res.json())
.then(res =>res['results'][0])
.catch(e => e);
}
@iamaamir
iamaamir / post.php
Created February 14, 2019 08:56
add a subscriber to mailchimp
<?php
if (isset($_POST['email'])) {
$email = $_POST['email'];
$template = strtr("{\"email_address\": \"%email%\",\"status\": \"subscribed\"}",
array('%email%' => $email));
$curl = curl_init();
@iamaamir
iamaamir / timestamp.py
Created October 4, 2018 13:44
simple Sublime Text 3 plugin to insert Author with timestamp
import sublime, sublime_plugin
from time import localtime, strftime
class InsertDatetimeCommand(sublime_plugin.TextCommand):
def run(self, edit):
format = "%d/%b/%Y/(%I.%M:%p)"
current_date = strftime(format, localtime())
content = "Author: Aamir khan (aamirkhan180@gmail.com)\n{}\n".format(current_date)
sel = self.view.sel();
for s in sel:
if s.empty():
@iamaamir
iamaamir / linkedlist.c
Created May 29, 2018 05:28
basic implementation of linkedlist in c
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
// const
#define AtBeginning 1
#define AtEnd 0
struct Node
{
import java.util.Scanner;
public class DecimalToBinary {
public static void main(String[] args) {
new DecimalToBinary().run();
}
public void toDecimal(int number){
int binary[] = new int[number];