Skip to content

Instantly share code, notes, and snippets.

View hanxiao's full-sized avatar
e/acc

Han Xiao hanxiao

e/acc
View GitHub Profile
@tadejsv
tadejsv / Instructions.md
Last active July 11, 2021 00:47
Jina 2.0 example

This script indexes ~800 poem verses from the huggingface poem_sentiment dataset, and uses a transformer model to index them, and performs a KNN search using FAISS module.

Before running, install all the requirements with these 3 commands:

conda create -n jina-2.0 -c conda-forge -c huggingface faiss-cpu datasets
conda activate jina-2.0
pip install jina sentence-transformers --pre
@gullyn
gullyn / flappy.html
Last active May 4, 2024 15:35
Flappy bird in 205 bytes (improved!)
<body onload=z=c.getContext`2d`,setInterval(`c.width=W=150,Y<W&&P<Y&Y<P+E|9<p?z.fillText(S++${Y=`,9,9|z.fillRect(p`}*0,Y-=--M${Y+Y},P+E,9,W),P))):p=M=Y=S=6,p=p-6||(P=S%E,W)`,E=49) onclick=M=9><canvas id=c>
@kianby
kianby / zproxy.py
Last active November 25, 2023 07:28
ZeroMQ, Python, XSUB / XPUB proxy
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import zmq
def main():
context = zmq.Context()
@EliotAndres
EliotAndres / benchmark.py
Created June 7, 2017 21:12
Tensorflow XLA benchmark
# '''
# A small Tensorflow XLA benchmark
#
# Original Author: Aymeric Damien
# Project: https://github.com/aymericdamien/TensorFlow-Examples/
# '''
import tensorflow as tf
@SnowMasaya
SnowMasaya / file0.txt
Created March 20, 2017 23:33
Tensorflow XLAによる高速化、メモリ効率化、サイズの最適化によるポータビリティ向上について ref: http://qiita.com/GushiSnow/items/a373b8d5d904566f65fd
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N]

10 Scala One Liners to Impress Your Friends

Here are 10 one-liners which show the power of scala programming, impress your friends and woo women; ok, maybe not. However, these one liners are a good set of examples using functional programming and scala syntax you may not be familiar with. I feel there is no better way to learn than to see real examples.

Updated: June 17, 2011 - I'm amazed at the popularity of this post, glad everyone enjoyed it and to see it duplicated across so many languages. I've included some of the suggestions to shorten up some of my scala examples. Some I intentionally left longer as a way for explaining / understanding what the functions were doing, not necessarily to produce the shortest possible code; so I'll include both.

1. Multiple Each Item in a List by 2

The map function takes each element in the list and applies it to the corresponding function. In this example, we take each element and multiply it by 2. This will return a list of equivalent size, compare to o

@plugnburn
plugnburn / README.md
Last active March 27, 2024 00:01
Statix - the simplest static website generator in bash

Statix - the simplest static website generator in Bash

Statix is a stand-alone Bash script aimed at generating full-featured, routable static websites from reusable HTML snippets. It features the most basic templating engine ever possible but allows to organize your content in a SEO-friendly way. All Statix-based websites contain these parts:

  • Templates: a directory where all HTML templates are stored
  • Route configuration: a file that maps each publicly accessible template to a SEO-friendly URL
  • Assets: a directory with optional files copied to the output website directory with no processing.

This script is also lightweight. Aside from some standard file management commands such as cp, mkdir and rm, the only serious dependency for Statix is GNU Grep compiled with PCRE support (i.e. the version that supports -P flag, included in most Linux distributions).

@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@suxue
suxue / WebSocketServer.sh
Created March 16, 2014 11:52
simple WebSocket Server make use of netcat
#!/bin/ksh
typeset port=$((RANDOM % 60000))
while ((port < 30000)); do
port=$((RANDOM % 60000))
done
typeset pipe=`mktemp -u`
mkfifo $pipe
trap "rm -f $pipe" INT
@windreamer
windreamer / portable_hash.pyx
Created October 12, 2013 13:57
Portable hash in Cython
from libc.stdint cimport int64_t
cdef tuple_hash(obj):
cdef int64_t mul = 1000003, l = len(obj), value = 0x345678, v
for i in obj:
l -= 1
v = portable_hash(i)
if v == -1:
return -1
value = (value ^ v) * mul
mul += <int64_t> (82520 + l * 2)