Skip to content

Instantly share code, notes, and snippets.

View xiaohan2012's full-sized avatar
🍠
eating sweat potatos

Xiao Han xiaohan2012

🍠
eating sweat potatos
View GitHub Profile
@jackrusher
jackrusher / gcloud-tramp.el
Created June 19, 2019 13:58
Tramping into GCloud instances from within emacs
;; make sure you've set your default project with:
;; gcloud config set project <project-name>
(require 'tramp)
(add-to-list 'tramp-methods
'("gcssh"
(tramp-login-program "gcloud compute ssh")
(tramp-login-args (("%h")))
(tramp-async-args (("-q")))
(tramp-remote-shell "/bin/sh")
@erikzenker
erikzenker / metis.cc
Created March 10, 2015 14:49
Metis usage example
#include <cstddef> /* NULL */
#include <metis.h>
#include <iostream>
// Install metis from:
// http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-5.1.0.tar.gz
// Build with
// g++ metis.cc -lmetis
@subfuzion
subfuzion / global-gitignore.md
Last active June 12, 2024 15:57
Global gitignore

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file:

  • Create a file called .gitignore in your home directory and add any filepath patterns you want to ignore.
  • Tell git where your global gitignore file is.

Note: The specific name and path you choose aren't important as long as you configure git to find it, as shown below. You could substitute .config/git/ignore for .gitignore in your home directory, if you prefer.

@tinybike
tinybike / weighted_median.py
Last active July 4, 2023 15:03
calculate a weighted median
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
calculate a weighted median
@author Jack Peterson (jack@tinybike.net)
"""
from __future__ import division
import numpy as np
def weighted_median(data, weights):
@ctokheim
ctokheim / cython_tricks.md
Last active March 4, 2024 23:27
cython tricks

Cython

Cython has two major benefits:

  1. Making python code faster, particularly things that can't be done in scipy/numpy
  2. Wrapping/interfacing with C/C++ code

Cython gains most of it's benefit from statically typing arguments. However, statically typing is not required, in fact, regular python code is valid cython (but don't expect much of a speed up). By incrementally adding more type information, the code can speed up by several factors. This gist just provides a very basic usage of cython.

@mblondel
mblondel / letor_metrics.py
Last active April 24, 2024 19:43
Learning to rank metrics.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
def ranking_precision_score(y_true, y_score, k=10):
"""Precision at rank k
Parameters
@jason-w
jason-w / gist:4969476
Created February 17, 2013 00:47
Helper functions that converts a MongoEngine Document to a Python Dict so it can be easily converted to JSON.
class Person (db.Document):
name = db.StringField(required=True)
created_date = db.ComplexDateTimeField(default=datetime.datetime.utcnow(), required=True)
def to_dict(self):
return helper.mongo_to_dict(self,[])
#helper.py
def mongo_to_dict(obj, exclude_fields):
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active June 21, 2024 01:45
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname