Skip to content

Instantly share code, notes, and snippets.

@ZhaofengWu
ZhaofengWu / install_zsh.sh
Last active May 14, 2024 13:05
Install zsh without root
#!/bin/bash
set -e
# OPTIONAL: zsh will not install without ncurses. IF your machine doesn't have ncurses, you need to install it first.
export CXXFLAGS=" -fPIC" CFLAGS=" -fPIC" CPPFLAGS="-I${HOME}/include" LDFLAGS="-L${HOME}/lib"
wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.2.tar.gz
tar -xzvf ncurses-6.2.tar.gz
cd ncurses-6.2
./configure --prefix=$HOME --enable-shared
@ctlllll
ctlllll / longest_chinese_tokens_gpt4o.py
Created May 13, 2024 19:53
Longest Chinese tokens in gpt4o
import tiktoken
import langdetect
T = tiktoken.get_encoding("o200k_base")
length_dict = {}
for i in range(T.n_vocab):
try:
length_dict[i] = len(T.decode([i]))
except:
@andersevenrud
andersevenrud / alacritty-tmux-vim_truecolor.md
Last active May 14, 2024 13:03
True Color (24-bit) and italics with alacritty + tmux + vim (neovim)

True Color (24-bit) and italics with alacritty + tmux + vim (neovim)

This should make True Color (24-bit) and italics work in your tmux session and vim/neovim when using Alacritty (and should be compatible with any other terminal emulator, including Kitty).

Testing colors

Running this script should look the same in tmux as without.

curl -s https://gist.githubusercontent.com/lifepillar/09a44b8cf0f9397465614e622979107f/raw/24-bit-color.sh >24-bit-color.sh
@BERRAMOU
BERRAMOU / CustomSerializer.php
Created March 8, 2019 11:16
Drupal 8 : Custom serializer example to render result as array instead of objects.
<?php
namespace Drupal\MY_MODULE\Plugin\views\style;
use Drupal\rest\Plugin\views\style\Serializer;
/**
* The style plugin for serialized output formats.
*
* @ingroup views_style_plugins
*
@hoangsonww
hoangsonww / text_summarizer.py
Created March 14, 2024 07:42
Text Summarization with AI
from transformers import pipeline, T5Tokenizer
def summarize_text(text, max_length=130, min_length=30, model_name='t5-small'):
"""
Summarizes long texts using a pre-trained model from Hugging Face's Transformers.
This enhanced version includes functionality to handle large texts by breaking them
into manageable chunks, addressing the token limit constraint of the model.
Parameters:
- text: The text to be summarized.
@vulcan25
vulcan25 / main.py
Created July 17, 2020 23:24 — forked from stewartadam/main.py
Simple Python proxy server based on Flask and Requests with support for GET and POST requests.
"""
A simple proxy server, based on original by gear11:
https://gist.github.com/gear11/8006132
Modified from original to support both GET and POST, status code passthrough, header and form data passthrough.
Usage: http://hostname:port/p/(URL to be proxied, minus protocol)
For example: http://localhost:5000/p/www.google.com
"""
import re
@ritog
ritog / alacritty.toml
Created October 6, 2023 10:58
Example configuration file for Alacritty and simple guide
# $HOME/.config/alacritty/alacritty.toml
# by Rito Ghosh 2023-10-06
# Alacritty now uses TOML formatting for its config files.
# This is a simple example.
# There are the specification here: https://github.com/alacritty/alacritty/blob/master/extra/man/alacritty.5.scd
# It is not obvious how it translates to TOML. But it is extremely straightforward.
# example: WINDOW, COLORS, etc. are tables, and should be represented as [window], [colors], respectively.
@kalomaze
kalomaze / modeling_mixtral.py
Created May 5, 2024 03:38
Fixed Mixtral training code for HF Transformers
# coding=utf-8
# Copyright 2023 Mixtral AI and the HuggingFace Inc. team. All rights reserved.
#
# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
# and OPT implementations in this library. It has been modified from its
# original forms to accommodate minor architectural differences compared
# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@Daenyth
Daenyth / debug_requests.py
Created August 27, 2015 14:35
Enable debug logging for python requests
import requests
import logging
import httplib
# Debug logging
httplib.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
req_log = logging.getLogger('requests.packages.urllib3')
req_log.setLevel(logging.DEBUG)
@rubyandcoffee
rubyandcoffee / Bootstrap - Rails 7
Last active May 14, 2024 12:59
Bootstrap with Rails 7
Adding Bootstrap to Rails 7
Reference: https://www.linkedin.com/pulse/rails-7-bootstrap-52-importmap-md-habibur-rahman-habib/
INSTRUCTIONS
1. Add the following to Gemfile:
gem "bootstrap"
gem "sassc-rails"