Skip to content

Instantly share code, notes, and snippets.

View keiya's full-sized avatar

keiya keiya

View GitHub Profile
@keiya
keiya / README.md
Created May 6, 2019 18:50
automatic gravity turn & circularize for Kerbal Space Program (KSP)
@keiya
keiya / add_header.sh
Created April 25, 2019 16:05
add a header for multiple files
#!/bin/bash
content=""
for var in "$@"
do
if [[ -f "$var" ]]; then
echo "$content" | cat - ${var} > /tmp/add_header_out && mv /tmp/add_header_out ${var}
fi
done
@keiya
keiya / gist:1190856
Created September 3, 2011 08:22
convert polar - cartesian
// thx tomy! http://www5.airnet.ne.jp/tomy/cpro/sslib12.htm
function cartesian2polar(x,y,z) {
var obj = new Object;
obj.r = Math.sqrt( x*x + y*y + z*z );
if (x != 0.0)
obj.phi = Math.atan2( y, x );
else {
if (y < 0.0)
@keiya
keiya / pow.rb
Created January 11, 2017 14:34
Proof Of Work in Ruby // this snippet shows an example of Bitcoin "proof of work"
require 'digest/sha2'
class ProofOfWork
@charset = (" ".."~").to_a
def self.solve(target,maxlength)
for i in 1..maxlength+1
ProofOfWork.chain(ProofOfWork.product(i)) do |candidate|
hashval = Digest::SHA256.hexdigest(candidate)
if hashval.start_with?(target)
@keiya
keiya / perio_iperf.sh
Created December 25, 2016 21:01
periodical iperf
IP=127.0.0.1
PORT=443
while true
do
DATE=$(date +%s)
iperf3 -c $IP -p $PORT -J --logfile ${DATE}_forward.json
iperf3 -R -c $IP -p $PORT -J --logfile ${DATE}_reverse.json
sleep 600
done
@keiya
keiya / dig.pl
Created December 18, 2012 11:50
dig web interface for minimalist
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
$| = 1;
if ($ENV{'QUERY_STRING'} ne '') {
print "Content-type:text/plain\n\n";
@keiya
keiya / midi_to_wav.sh
Last active September 26, 2016 00:53
MIDI to WAV / WavPack. For extreme high audio quality, we use 64bit/32bit floating-point intermediate file.
#!/bin/bash
BANKSELECT='gm'
SF="$HOME/Timbres Of Heaven GM_GS_XG_SFX V 3.2 Final.sf2"
find "$1" -type f -iname "*.mid" -print0 | while IFS= read -r -d '' fullfile; do
file=`basename ${fullfile}`
fluidsynth -g 0.01 -o synth.midi-bank-select=$BANKSELECT -o synth.midi-channels=256 -o synth.polyphony=4096 -r 48000 -O double -F "${file}_raw.wav" "${SF}" "${fullfile}"
sox --norm=-1 "${file}_raw.wav" -b 32 -e signed-integer "${file}.wav"
rm "${file}_raw.wav" &
@keiya
keiya / separate.c
Created February 22, 2016 15:46
Split Motion-JPEG (MJPEG) Stream into JPEG files; for Syma X5SW WiFi FPV Camera. ; also included realtime streaming shell script which is using VLC.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_FRAME_SIZE 256*1024 // KB
#define CONTENT_LENGTH "Content-Length: "
#define PAYLOAD "\r\n"
int main()
{
var di = 0.81 * temp + 0.01 * rh * (0.99 * temp - 14.3) + 46.3 ;
@keiya
keiya / gist:8165245
Created December 28, 2013 22:53
Grooveshark "are you there?" canceller : automatically click the resume button!
var timer = setInterval(function(){
var $btn = $(".btn.btn-large.submit.btn-primary");
if ($btn.length > 0) {
$btn.click();
console.debug("Button clicked");
}
},1000);