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
@kendru
kendru / simpleslider.jquery.js
Created October 12, 2012 06:00
Simple jQuery image slider
// Image slider, complete with lazy loading.
(function ($) {
$.fn.sliderize = function( options ) {
var settings = $.extend({
srcAttrib: "src", // data attribute containing image source
delayTime: 6000,
transitionTime: 1000,
randomize: false, // "randomize" the slides
width: 700,
height: 276
@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
@majodev
majodev / capture.js
Created July 22, 2014 17:21
Capture screenshots (png) from multiple sites with phantomjs
// How to: save as capture.js and run with "phantomjs capture.js"
// Setup by modifying URLS, PAGE_WIDTH AND PAGE_HEIGHT constants!
// Hint: set PAGE_WIDTH or PAGE_HEIGHT to 0 to capture full page!
// modified version of script at http://www.cameronjtinker.com/post/2011/09/26/Take-Screenshot-of-all-HTML-documents-in-a-folder-using-PhantomJS.aspx
var PAGE_WIDTH = 960;
var PAGE_HEIGHT = 640;
var URLS = [
"http://github.com",
@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
@sdesalas
sdesalas / TwitterClient.cs
Last active May 26, 2023 03:34
An ultra-lightweight Twitter client in C# using OAuth
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Security.Cryptography;
using System.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Web;
@dherman
dherman / emacs-cheat-sheet.md
Created August 2, 2012 16:22
My emacs cheat sheet

In penance for cracking stupid jokes on Twitter, here's my Emacs cheat sheet. Emacs has a steep learning curve, so I've tried to order them by importance so you could learn them in stages.

One overall rule of thumb: pay attention to the minibuffer (the line at the bottom of the editor). It will often guide you through a process, and also gives you hints about what state you're in, such as the middle of a multi-chord sequence.

The other rule of thumb: when in doubt, C-g it out.

Basics (mandatory)

You simply can't get by without having these at your fingertips.

@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
@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
'''
@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)
@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