Skip to content

Instantly share code, notes, and snippets.

View srishanbhattarai's full-sized avatar
💭
Make software fast again

Srishan srishanbhattarai

💭
Make software fast again
View GitHub Profile
@srishanbhattarai
srishanbhattarai / docker-names.go
Created April 18, 2018 10:25
Scrape list of Docker container names. Run `go run docker-names.go >> names.txt`
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
)
func main() {
t := time.After(10 * time.Second)
@srishanbhattarai
srishanbhattarai / android.txt
Last active March 22, 2025 04:46
Android Emulator CPU/Memory high usage solution
https://stackoverflow.com/questions/37063267/high-cpu-usage-with-android-emulator-qemu-system-i386-exe
The cause of the constant CPU usage is the sound. If you do not need sound in your emulator you can disable it by editing the AVD's config file.
Change/add those two lines
hw.audioInput=no
hw.audioOutput=no
On Linux/Mac the file is located at ~/.android/avd/<AVD_Name>.avd/config.ini
On Windows the file is located at C:\Users\<username>\.android\avd\<AVD_Name>.avd\config.ini
@srishanbhattarai
srishanbhattarai / repeat.js
Created July 28, 2018 16:13
Create an array using a map function
/**
* Create an array of length 'N' by executing repeaterFn for each item.
* This is useful where a method like `getItem()` can return a random item,
* and it can be repeated over N times.
*
* @param {function} repeaterFn
* @param {number} N=5
* @returns {Array}
*/
const repeat = (repeaterFn, N = 5) => Array(...Array(N)).map(repeaterFn)
@srishanbhattarai
srishanbhattarai / calculator.rs
Last active February 4, 2019 06:21
Example Calculator struct for the Neovim plugin blog post
struct Calculator;
impl Calculator {
fn new() -> Calculator {
Calculator {}
}
// Add a vector of numbers.
fn add(&self, nums: Vec<i64>) -> i64 {
nums.iter().sum::<i64>()
@srishanbhattarai
srishanbhattarai / eventhandler.rs
Created February 4, 2019 06:22
EventHandler example instance for the Neovim plugin blog
extern crate neovim_lib;
use neovim_lib::{Neovim, NeovimApi, Session};
struct EventHandler {
nvim: Neovim,
calculator: Calculator,
}
impl EventHandler {
@srishanbhattarai
srishanbhattarai / messages.rs
Last active February 4, 2019 06:29
Messages.rs for the Neovim Plugin blog
enum Messages {
Add,
Multiply,
Unknown(String),
}
impl From<String> for Messages {
fn from(event: String) -> Self {
match &event[..] {
"add" => Messages::Add,
@srishanbhattarai
srishanbhattarai / eventhandler2.rs
Created February 4, 2019 06:40
Skeleton of the recv() method for eventhandler
// Rest of the stuff remains the same.
fn recv(&mut self) {
let receiver = self.nvim.session.start_event_loop_channel();
for (event, values) in receiver {
match Messages::from(event) {
Messages::Add => {
// do stuff
}
@srishanbhattarai
srishanbhattarai / eventhandler3.rs
Last active February 4, 2019 07:05
Implementation of data serialization for Neovim plugins
fn recv(&mut self) {
let receiver = self.nvim.session.start_event_loop_channel();
for (event, values) in receiver {
match Messages::from(event) {
// Handle 'Add'
Messages::Add => {
let nums = values
.iter()
.map(|v| v.as_i64().unwrap())
@srishanbhattarai
srishanbhattarai / eventhandler4.rs
Last active February 4, 2019 09:26
Echoing back responses to neovim
fn recv(&mut self) {
let receiver = self.nvim.session.start_event_loop_channel();
for (event, values) in receiver {
match Messages::from(event) {
// Handle 'Add'
Messages::Add => {
let nums = values
.iter()
.map(|v| v.as_i64().unwrap())
" Initialize the channel
if !exists('s:calculatorJobId')
let s:calculatorJobId = 0
endif
" The path to the binary that was created out of 'cargo build' or 'cargo build --release". This will generally be 'target/release/name'
let s:bin = '/path/to/rust-binary'
" Entry point. Initialize RPC. If it succeeds, then attach commands to the `rpcnotify` invocations.
function! s:connect()