Skip to content

Instantly share code, notes, and snippets.

@shadiakiki1986
shadiakiki1986 / example_1.txt
Last active October 4, 2023 08:53
aws cli cloudtrail + jq examples
# list latest 10 event names and the next token
aws cloudtrail lookup-events \
--max-items 10 \
--lookup-attributes AttributeKey=EventSource,AttributeValue=ec2.amazonaws.com \
--lookup-attributes AttributeKey=ReadOnly,AttributeValue=false \
--starting-token "eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxMH0=" | \
jq '.Events[].EventName,.NextToken'
"ModifyInstanceAttribute"
@shadiakiki1986
shadiakiki1986 / steps.md
Last active May 6, 2019 12:13
Restoring an elasticsearch snapshot

General

These are steps to restore an elasticsearch snapshot from one machine to another

Steps

Copy zip of snapshot from s3

sudo mkdir /data
@shadiakiki1986
shadiakiki1986 / README.md
Last active April 17, 2019 10:02
chemlambda pred(3): graphviz dot file equivalent to mol file

Generating a graphviz dot file equivalent to the mol file of pred(3) in chemlambda v2: pred_3.mol (original name was erroneous)

The lambda calculus expression for pred(3) (predecessor(3) == 2) is PRED := λn.λf.λx.n (λg.λh.h (g f)) (λu.x) (λu.u) (ref wikipedia)

Writing the above expression as nodes in a graph leads to the below graph. The corresponding dot file was written manually and available further below in this gist. An annotated version of pred_3.mol to help compare it to pred_3.dot is available further below in this gist.

To generate the dot file automatically from lambda terms, check http://www.teamshadi.net/chemlambda-js/ (a fork from this jsfiddle ). Its current output for pred(3) matches with the manually specified graph below.

Version 4 (2019-04-11): shifted indeces back by 1 (e.g. L1 to L0) t

@shadiakiki1986
shadiakiki1986 / README.md
Last active April 26, 2019 19:28
Ackermann function illustrated

The below is an ackermann function implementation in awk based on the one on rosettacode.org and modified for higher verbosity to illustrate the details of calculations behind the ackermann function's recursion.

For example, the following shows Ackermann(2,2)

> awk -v m=2 -v n=2 -f ackermann_illustrated.awk
@shadiakiki1986
shadiakiki1986 / so-51469446-bounty.ipynb
Created March 19, 2019 04:07
SO 51469446 bounty.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shadiakiki1986
shadiakiki1986 / README.md
Last active July 27, 2021 18:08
Wrap "dbxcli get" command to download files from a dropbox dir
@shadiakiki1986
shadiakiki1986 / .block
Created September 28, 2018 08:02 — forked from mbostock/.block
Force-Directed Graph
license: gpl-3.0
height: 600
@shadiakiki1986
shadiakiki1986 / README.md
Last active June 21, 2018 05:11
steps for installing jupyterhub

These are my notes while installing jupyterhub on an AWS EC2 instance running Ubuntu 16.04

Prerequisites

  • install python3, pip3
    • sudo apt-get update && sudo apt-get install python3 python3-pip
  • - ~~~`pip3 install pew`~~~
    
@shadiakiki1986
shadiakiki1986 / stride_group.py
Last active June 7, 2018 07:52
striding a matrix for RNN input
# Fiddle at
# https://pyfiddle.io/fiddle/a14865cf-38c9-48d6-b90a-f5bedc7a5b6e/?m=Saved%20fiddle
#
# reshape a matrix M x N into M x P x (N-P) while creating overlapping rows
# Useful for LSTM input
import numpy as np
import pandas as pd
def stride_group(group, lahead):
@shadiakiki1986
shadiakiki1986 / README.md
Last active October 13, 2022 18:22
Run a Scrapy spider in a Celery Task (in django)

My first shot at fixing this was in tasks.py file below.

But then that just gave a "unhandled error in deferred", so I went on to use CrawlRunner.

That showed no output at all anymore, and didn't run as expected.

Eventually, I just settled on CELERY_WORKER_MAX_TASKS_PER_CHILD=1=1 in settings.py

Note: CELERY_WORKER_MAX_TASKS_PER_CHILD=1 is for django. Celery without django probably drops the CELERY_ prefix