Skip to content

Instantly share code, notes, and snippets.

View MihailJP's full-sized avatar

MihailJP MihailJP

View GitHub Profile
@MihailJP
MihailJP / scala.xml
Last active April 19, 2024 01:14
Notepad++ syntax highlighting definition file for Scala
<NotepadPlus>
<UserLang name="Scala" ext="scala" udlVersion="2.0">
<Settings>
<Global caseIgnored="no" allowFoldOfComments="no" forceLineCommentsAtBOL="no" foldCompact="no" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="yes" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments" id="0">00// 01 02 03/* 04*/</Keywords>
<Keywords name="Numbers, additional" id="1"></Keywords>
<Keywords name="Numbers, prefixes" id="2">0x</Keywords>
@MihailJP
MihailJP / gpufan.bash
Created November 5, 2013 13:02
Script to control the fan speed automatically (works only for NVIDIA graphic cards)
#!/bin/bash
# Script to control the fan speed automatically
setFanSpeed() {
eval "nvidia-settings -a GPUFanControlState=1 -a [fan:0]/GPUCurrentFanSpeed=$1 > /dev/null"
}
cleanup() {
eval "nvidia-settings -a GPUFanControlState=0"
@MihailJP
MihailJP / complex.lua
Created August 28, 2012 16:41
Complex numbers for Lua
--[[
--
-- *** Complex numbers for Lua ***
--
--]]
-- Module "cmath" ... mathematic functions for complex numbers
module("cmath", package.seeall)
@MihailJP
MihailJP / cobol.xml
Last active October 18, 2022 20:04
Kate syntax highlighting definition file for COBOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd" [
<!ENTITY picsig "\bPIC(TURE)?(\s+IS)?\s+">
<!ENTITY verbs "\b(((END-)?(ACCEPT|ADD|CALL|COMPUTE|DELETE|DISPLAY|DIVIDE|EVALUATE|IF|MULTIPLY|PERFORM|READ|RECEIVE|RETURN|REWRITE|SEARCH|START|STRING|SUBTRACT|UNSTRING|WRITE))|ALTER|ASSIGN|CHAIN|CLOSE|CONTINUE|CONTROL|COPY|COUNT|ELSE|ENABLE|ERASE|EXIT|GENERATE|GO|GOBACK|IGNORE|INITIALIZE|INITIATE|INSPECT|INVOKE|MERGE|MOVE|OPEN|RELEASE|REPLACE|RESERVE|RESET|REWIND|ROLLBACK|RUN|SELECT|SEND|SET|SORT|STOP|SUM|SUPPRESS|TERMINATE|THEN|TRANSFORM|UNLOCK|UPDATE|USE|WAIT|WHEN)\b(?!-)">
<!ENTITY usages "\b(BINARY|BINARY-C-LONG|BINARY-CHAR|BINARY-DOUBLE|BINARY-LONG|BINARY-SHORT|COMP|COMP-1|COMP-2|COMP-3|COMP-4|COMP-5|COMP-X|COMPUTATIONAL|COMPUTATIONAL-1|COMPUTATIONAL-2|COMPUTATIONAL-3|COMPUTATIONAL-4|COMPUTATIONAL-5|COMPUTATIONAL-X|FLOAT-BINARY-16|FLOAT-BINARY-34|FLOAT-BINARY-7|FLOAT-DECIMAL-16|FLOAT-DECIMAL-34|FLOAT-EXTENDED|FLOAT-LONG|FLOAT-SHORT|FUNCTION-POINTER|INDEX|NATIONAL|PACKED-DECIMAL|PO
@MihailJP
MihailJP / d_copy.lua
Created October 22, 2012 14:47
Shallow- and deep-copy of table in Lua
function clone (t) -- deep-copy a table
if type(t) ~= "table" then return t end
local meta = getmetatable(t)
local target = {}
for k, v in pairs(t) do
if type(v) == "table" then
target[k] = clone(v)
else
target[k] = v
end
@MihailJP
MihailJP / rational.hpp
Created January 17, 2013 16:40
Fraction class template
#pragma once
#include <stdexcept>
// Calculate GCD (for reduction)
template<typename T> T gcd(T x, T y) {
// Euclidean algorithm
T val1 = (x < y) ? y : x, val2 = (x < y) ? x : y;
T* m = &val1; T* n = &val2; T* tmpptr = nullptr;
while (true) {
@MihailJP
MihailJP / gcd.fth
Created May 17, 2014 11:25
GCD and LCM of two numbers, implemented with Forth
\ This implements Euclidean algorithm in Forth
: gcd ( X Y )
2dup <= if swap ( Y X ) then
( X Y )
begin
tuck ( Y X Y )
mod ( Y Z )
dup ( Y Z Z )
0= until ( Y Z )
( Y 0 )
@MihailJP
MihailJP / test2038.c
Created October 8, 2012 15:04
Check if your time_t implementation will work after 2038
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main () {
time_t time_num[5] = {(time_t)0x00000000, (time_t)0x7fffffff, (time_t)0x80000000, (time_t)0xffffffff,};
struct tm* parsed_time; unsigned int i;
printf("sizeof(time_t) is %d.\n", sizeof(time_t));
for (i = 0; i < 4; i++) {
parsed_time = gmtime(&(time_num[i]));
@MihailJP
MihailJP / gcd.lua
Created January 26, 2014 11:25
Implementation of Euclidian algorithm
function gcd(a, b)
local x = a; local y = b
repeat
if x > y then
x = math.fmod(x, y)
else
y = math.fmod(y, x)
end
until x == 0 or y == 0
return x + y
@MihailJP
MihailJP / stat.hs
Created July 15, 2013 06:55
Functions for statistics
-- Functions for statistics
import Data.List
-- Averages
average p = (sum p) / (fromIntegral $ length p) -- arithmetic mean
geomean p = (product p) ** (1.0 / (fromIntegral $ length p)) -- geometric mean
harmean p = (fromIntegral $ length p) / (sum $ map (\x -> 1.0 / x) p) -- harmonic mean
rms p = sqrt $ average $ map (\x -> x * x) p -- quadratic mean (RMS)