Skip to content

Instantly share code, notes, and snippets.

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

Tom Bush tomfbush

🏠
Working from home
View GitHub Profile
@abhishekkrthakur
abhishekkrthakur / slack_notifier.py
Created December 6, 2019 07:53
Slack notification from python
import os
import requests
import json
SLACK_WEBHOOK= os.environ.get("SLACK_WEBHOOK")
def send_message(messages, channel="abhishek", username="beast"):
"""
:param messages: list of texts
@endolith
endolith / DFT_ANN.py
Last active October 11, 2024 07:04
Training neural network to implement discrete Fourier transform (DFT/FFT)
"""
Train a neural network to implement the discrete Fourier transform
"""
import matplotlib.pyplot as plt
import numpy as np
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
N = 32
batch = 10000
@wiso
wiso / covariance_to_correlation.py
Created March 20, 2018 08:33
Compute correlation matrix from covariance matrix using numpy
import numpy as np
def correlation_from_covariance(covariance):
v = np.sqrt(np.diag(covariance))
outer_v = np.outer(v, v)
correlation = covariance / outer_v
correlation[covariance == 0] = 0
return correlation
@gajeshbhat
gajeshbhat / strToInt.py
Last active October 31, 2023 19:41
Convert k to Integer thousand Python.
def convert_str_to_number(x):
total_stars = 0
num_map = {'K':1000, 'M':1000000, 'B':1000000000}
if x.isdigit():
total_stars = int(x)
else:
if len(x) > 1:
total_stars = float(x[:-1]) * num_map.get(x[-1].upper(), 1)
return int(total_stars)
@tanaikech
tanaikech / submit.md
Created September 7, 2017 03:55
Uploading Image Files to Slack Using Incoming Webhooks by Google Apps Script

Uploading Image Files to Slack Using Incoming Webhooks by Google Apps Script

This sample script is for uploading image files to Slack using Incoming Webhooks by Google Apps Script.

When users try to upload image files to Slack using Incoming Webhooks, it has been known that although the access token is required to directly upload them, Incoming Webhooks can upload them by using the tag of image_url. In this sample script, it uploads image files (BMP, GIF, JPEG and PNG) on Google Drive to Slack using Incoming Webhooks. The script is written by Google Apps Script.

In this sample, It supposes that there are image files on Google Drive.

Script :

We can make this file beautiful and searchable if this error is corrected: It looks like row 9 should actually have 6 columns, instead of 4 in line 8.
datasetName,about,link,categoryName,cloud,vintage
Microbiome Project,American Gut (Microbiome Project),https://github.com/biocore/American-Gut,Biology,GitHub,NA
GloBI,Global Biotic Interactions (GloBI),https://github.com/jhpoelen/eol-globi-data/wiki#accessing-species-interaction-data,Biology,GitHub,NA
Global Climate,Global Climate Data Since 1929,http://en.tutiempo.net/climate,Climate/Weather,,1929
CommonCraw 2012,3.5B Web Pages from CommonCraw 2012,http://www.bigdatanews.com/profiles/blogs/big-data-set-3-5-billion-web-pages-made-available-for-all-of-us,Computer Networks,,2012
Indiana Webclicks,53.5B Web clicks of 100K users in Indiana Univ.,http://cnets.indiana.edu/groups/nan/webtraffic/click-dataset/,Computer Networks,,NA
Criteo click-through,Criteo click-through data,http://labs.criteo.com/2015/03/criteo-releases-its-new-dataset/,Computer Networks,,NA
ICWSM 2009,ICWSM Data Challenge (since 2009),http://icwsm.cs.umbc.edu/,Data Challenges,,2009
KDD Cup,KDD Cup by Tencent 2012,http://www.kddcup2012.org/,Data
@devStepsize
devStepsize / slack_slash_cmd.py
Created April 21, 2016 23:12
Server-side logic to handle a Slack slash command using Python and Flask
'''
This is an example of the server-side logic to handle slash commands in
Python with Flask.
Detailed documentation of Slack slash commands:
https://api.slack.com/slash-commands
Slash commands style guide:
https://medium.com/slack-developer-blog/slash-commands-style-guide-4e91272aa43a#.6zmti394c
'''
@tatome
tatome / saliency.py
Created February 11, 2016 20:29
Simple Itty-Koch-Style Saliency Maps
# coding=utf-8
#
#!/usr/bin/python
#
# Copyright 2013 Johannes Bauer, Universitaet Hamburg
#
# This file is free software. Do with it whatever you like.
# It comes with no warranty, explicit or implicit, whatsoever.
#
# This python script implements an early version of Itti and Koch's
@decabyte
decabyte / nb_remove_output.py
Last active December 21, 2023 02:32 — forked from damianavila/remove_output.py
Remove output from Jupyter notebook from the command line
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Remove output from existing Jupyter Notebooks.
Modified from remove_output by Minrk, damianavila, gabraganca.
References:
[0]: https://github.com/jupyter/nbformat
[1]: http://nbformat.readthedocs.org/en/latest/index.html
@gluc
gluc / Desc_JSON_to_df.md
Last active June 19, 2023 02:32
Convert a complex JSON to an R data.frame

This gist shows how to convert a nested JSON file to an R data.frame. To do this, it uses jsonlite and data.tree.

The gist contains two examples: one is a bit simpler, the second one a bit more advanced.

Example 1

In the first example, we download all the repos from Hadley Wickham's Github account from https://api.github.com/users/hadley/repos . This JSON contains a nested owner object. The code shows how to convert that in a flat data.frame in three statements:

  1. line 5: download
  2. line 8: convert to data.tree