Skip to content

Instantly share code, notes, and snippets.

View maciejskorski's full-sized avatar

Maciej Skorski maciejskorski

View GitHub Profile
@maciejskorski
maciejskorski / abstractsyntaxtree_demo.ipynb
Last active May 9, 2023 04:20
abstractsyntaxtree_demo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maciejskorski
maciejskorski / clang_example.out
Created May 7, 2023 10:02
non-trivial clang usage example
print_lcp_config_options
struct netdissect_options * TypeKind.POINTER arg declared in ./tcpdump/print-ppp.c:L403,C39-L403,C59 netdissect_options declared in ./tcpdump/netdissect.h:L161
const unsigned char TypeKind.ELABORATED arg declared in ./tcpdump/print-ppp.c:L403,C61-L403,C73 u_char declared in /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/sys/_types/_u_char.h:L30
const unsigned int TypeKind.ELABORATED arg declared in ./tcpdump/print-ppp.c:L403,C75-L403,C86 u_int declared in /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/sys/_types/_u_int.h:L30
print_ipcp_config_options
struct netdissect_options * TypeKind.POINTER arg declared in ./tcpdump/print-ppp.c:L404,C40-L404,C60 netdissect_options declared in ./tcpdump/netdissect.h:L161
const unsigned char * TypeKind.POINTER arg declared in ./tcpdump/print-ppp.c:L404,C62-L404,C77 u_char declared in /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/sys/_types/_u_char.h:L30
unsigned int TypeKind.ELABO
@maciejskorski
maciejskorski / requirements.txt
Last active April 21, 2023 14:30
kaggle python docker packages
# gcr.io/kaggle-images/python:latest
# checked on April 21 2023
# root@9735f873cb2d:/# pip list show
Package Version Editable project location
-------------------------------------- -------------- -------------------------
absl-py 1.4.0
accelerate 0.12.0
access 1.1.9
affine 2.4.0
aiobotocore 2.5.0
@maciejskorski
maciejskorski / config
Created April 21, 2023 11:34
An example of SSH config for Google Cloud
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host snarto_kaggle_cpu
# update the instance IP under console.cloud.google.com/compute/instances -> more (...) -> network details
HostName 34.170.120.99
# add the public part under console.cloud.google.com/compute/metadata
IdentityFile ~/.ssh/id_rsa
# match the name under the SSH key
User maciej.skorski
Port 22
@maciejskorski
maciejskorski / gist:6fb8b066145ebef53d85adb99db8a9b2
Created December 18, 2020 21:33
profiling custom blocks of TF code
# wrap the TF code to be profiled with <start> and <stop> methods as below
tf.profiler.experimental.start('logs/profile')
for (x,y) in data:
train_step(x,y)
tf.profiler.experimental.stop()
@maciejskorski
maciejskorski / logistic_TF
Created December 18, 2020 21:28
efficient logistic regression
## train a logistic regression (images 28x28 and 10 classes)
w = tf.Variable(tf.random.normal(shape=(28*28,10),stddev=0.1),trainable=True)
optimizer = tf.optimizers.SGD(0.01)
@tf.function
def train_step(x, y):
with tf.GradientTape() as tape:
all_logits = tf.matmul(x,w) # (n_batch,n_class)
y_logits = tf.gather(all_logits,y,batch_dims=1) # (n_batch,)
def SparseCategoricalCrossentropy(labels,logits):
''' labels: shape [n_batch] contains true classes as numbers from 0 to n_classes-1
logits: shape [n_batch,n_classes], predicted log probabilities '''
Z = tf.reduce_logsumexp(logits,axis=-1)
lookup_labels = tf.stack([tf.range(tf.shape(labels)[0]),tf.cast(labels,tf.int32)],1)
true_logits = tf.gather_nd(logits,lookup_labels,batch_dims=0)
return -true_logits + Z
@maciejskorski
maciejskorski / skipgram_generator.txt
Last active April 4, 2020 18:52
skipgram generator
from itertools import islice,chain
from collections import deque
def gen_skipgrams(itr,window=1,symmetric=False,Q=None):
itr = iter(itr)
if not Q:
Q = deque(islice(itr,window-1),maxlen=window)
append = Q.append
for i in itr:
for j in Q: