Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / gem-reset
Last active Oct 5, 2020
Remove all non default gems. For ruby 2.0.0
View gem-reset
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`gem list -d`.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
next if match[1].empty? # it's the only version if this match is empty
View uint_vs_float.rs
union U {
u32: u32,
u64: u64,
f32: f32,
f64: f64,
}
fn main() {
let u32 = U { u32: 1 };
let u64 = U { u64: 1 };
View syncolor.vim
let highlights = execute('highlight')
let highlights = substitute(highlights, '\n\s\+', ' ', 'g')
let highlights = split(highlights, '\n')
call map(highlights, "split(v:val, '\\s\\+xxx\\s\\+')[0]")
for group in highlights
execute 'highlight' group 'NONE'
endfor
@nixpulvis
nixpulvis / median.rb
Created Apr 28, 2020
Median of Medians Algorithm
View median.rb
# Common median algorithm, which averages the two middle
# values when needed.
def median(list)
sorted = list.sort
half = (list.size - 1) / 2
if list.size.even?
(sorted[half] + sorted[half+1]) / 2.0
else
sorted[half]
end
@nixpulvis
nixpulvis / segv.c
Last active Mar 19, 2020
Intel pthreads Issue
View segv.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
static pthread_t thread;
static pthread_mutex_t mutex;
void* work(void* ptr)
{
pthread_detach(pthread_self());
@nixpulvis
nixpulvis / dhm.rs
Created Mar 16, 2020
Diffe-Hellman-Merkle Key Exchange Demonstration (using curves crate)
View dhm.rs
//! ```cargo
//! [dependencies]
//! rand = "0.3.16"
//! curves = { git = "https://gitlab.com/neucrypt/curves", branch = "release" }
//! ```
extern crate rand;
extern crate curves;
use curves::{Secp, SecpOrd, ECGroup, Ford};
/// This demonstrates the math beneath a Diffe-Hellman-Merkle key exchange, and
@nixpulvis
nixpulvis / unicode.txt
Created Jan 27, 2020
Test Unicode File
View unicode.txt
From xiangkangzzz@163.com Sat Sep 28 21:28:52 2019
Date: Sat, 28 Sep 2019 12:23:51 +0800
From: 0 <xiangkangzzz@163.com>
Reply-To: billie@joawamould.com
Subject: E-017-00260_28
Message-ID: <201909281224045885357@163.com>
X-Mailer: Foxmail 7, 0, 1, 91[cn]
Dear ask
@nixpulvis
nixpulvis / fullscreen.c
Created Dec 4, 2013
Fullscreen OpenGL with GLUT
View fullscreen.c
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include <GLUT/glut.h>
#include <stdio.h>
@nixpulvis
nixpulvis / windows_install.sh
Created Feb 7, 2019
Install Windows 10 From Linux
View windows_install.sh
fdisk /dev/sdY
# create single partition type 7+bootable partition
mkfs.ntfs -f /dev/sdY1
ms-sys -7 /dev/sdY
mount -o loop win7.iso /mnt/iso
mount /dev/sdY1 /mnt/usb
cp -r /mnt/iso/* /mnt/usb/
@nixpulvis
nixpulvis / process.rs
Last active Sep 28, 2019
Simple Rust Threaded TCP Client Server
View process.rs
use std::io::prelude::*;
use std::thread;
use std::net::{TcpStream, TcpListener};
fn network_process() {
let listener = TcpListener::bind("127.0.0.1:1337").unwrap();
let mut handlers = Vec::new();
match listener.accept() {
Ok((mut socket, addr)) => {
You can’t perform that action at this time.