Skip to content

Instantly share code, notes, and snippets.

View gzxultra's full-sized avatar
🍎
eating apple

Zhixiang gzxultra

🍎
eating apple
  • Seattle, WA
View GitHub Profile
@DazWorrall
DazWorrall / Output
Created February 9, 2012 13:06
Testing file upload handling in Flask
in upload handler
in file close
..
----------------------------------------------------------------------
Ran 2 tests in 0.021s
OK
@Alexis-D
Alexis-D / psort.c
Created February 27, 2012 11:20
Parallel Radix Sort with OpenMP
#include <stdlib.h>
#include <string.h>
#define INITIAL_SHIFT (((sizeof (long long)) - 1) * 010)
#define NTHREADS 64
#define SWITCH_TO_INSERTION 16
#define SWITCH_TO_QSORT 8192
#define DO_NOT_RADIX 2626144
/*
@ChickenProp
ChickenProp / gist:3194723
Created July 28, 2012 20:45
The Liang-Barsky algorithm for line-rectangle collisions

The Liang-Barsky algorithm is a cheap way to find the intersection points between a line segment and an axis-aligned rectangle. It's a simple algorithm, but the resources I was pointed to didn't have particularly good explanations, so I tried to write a better one.

Consider a rectangle defined by x_min ≤ x ≤ x_max and y_min ≤ y ≤ y_max, and a line segment from (x_0, y_0) to (x_0 + Δ_x, y_0 + Δ_y). We'll be assuming at least one of Δ_x and Δ_y is nonzero.

Image depicting the situation

(I'm working with Flash, so I'll be using the convention that y increases as you go down.)

We want to distinguish between the following cases:

@bradley219
bradley219 / .gitignore
Last active July 22, 2024 14:04
PID C++ implementation
.DS_Store
@kachayev
kachayev / topological.py
Last active December 30, 2022 10:21
Topological sort with Python (using DFS and gray/black colors)
# Simple:
# a --> b
# --> c --> d
# --> d
graph1 = {
"a": ["b", "c", "d"],
"b": [],
"c": ["d"],
"d": []
}
@edokeh
edokeh / index.js
Last active July 23, 2024 14:08
佛祖保佑,永无 BUG
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@clemsos
clemsos / gensim_workflow.py
Last active February 22, 2022 11:09
How to calculate TF-IDF similarity matrix of a complete corpus with Gensim
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This script just show the basic workflow to compute TF-IDF similarity matrix with Gensim
OUTPUT :
@nightire
nightire / .vimrc
Last active May 25, 2022 03:14
Vim 基础配置
set nocompatible " use vim defaults
set t_RV= " http://bugs.debian.org/608242
" set runtimepath=$VIMRUNTIME " turn off user scripts, https://github.com/igrigorik/vimgolf/issues/129
syntax on " turn syntax highlighting on by default
filetype on " detect type of file
filetype indent on " load indent file for specific file type
set nobackup " do not keep a backup file
set novisualbell " turn off visual bell
@FlorianWolters
FlorianWolters / CMakeLists.txt
Last active May 21, 2024 17:29
Add Boost C++ Libraries as a dependency with plain CMake
# Copyright (c) 2014-2023 Florian Wolters
# MIT License
cmake_minimum_required(VERSION 3.26.3)
project(
"hello_boost_with_cmake"
VERSION 2.0.0
LANGUAGES CXX)
@mskeving
mskeving / reverse.py
Created April 10, 2015 19:23
Reverse a list in python
# Note, these functions are only for reversing lists in Python.
# In Python, strings are immutable, meaning you can't change their value.
# In other languages, like Ruby, this would be possible.
# If you want to reverse a string, you can use .split(), but that
# returns a list of characters, which means you are no longer doing
# it in place. This gives you O(n) space complexity.
# O(n) space, because the new list could be arbitrarily large
# O(n) time to go through each item in list.