Skip to content

Instantly share code, notes, and snippets.

@SergKolo
SergKolo / Simple "ring buffer" table
Created July 19, 2020 05:03
Simple "ring buffer" table. Mainly intended to be the most basic example of how logging can be implemented in SQLite
DROP TABLE IF EXISTS ring_log;
CREATE TABLE ring_log (
timestamp INT,
data TEXT
);
CREATE TRIGGER remove_oldest BEFORE INSERT ON ring_log
WHEN ( SELECT COUNT(*)>5 FROM ring_log )
BEGIN
DELETE FROM ring_log WHERE timestamp in ( SELECT timestamp FROM ring_log LIMIT 1 );
@SergKolo
SergKolo / minicat.c
Created November 29, 2019 09:49
Basically simplified example from getline(2) man page with optional stdin vs file reading
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
FILE *stream;
char *line = NULL;
size_t len = 0;
ssize_t nread;
@SergKolo
SergKolo / cond_trigger.sqlite
Created October 27, 2018 22:26
conditional trigger in sqlite
DROP TABLE IF EXISTS tb1;
DROP TABLE IF EXISTS tb2;
DROP TABLE IF EXISTS ch;
CREATE TABLE tb1 (a INT, b TEXT);
INSERT INTO tb1 VALUES (1,'foo'),(2,'bar');
CREATE TABLE tb2 AS SELECT * FROM tb1;
CREATE TABLE ch (choice TEXT);
CREATE TRIGGER conditional_1 AFTER INSERT ON ch
WHEN new.choice = 'tb1'
@SergKolo
SergKolo / gist:86158edcf88f8cb5afcc78143f86c32c
Created October 13, 2018 17:43
simpsons rule in torture language called Matlab
function S_n = simpsons(x,f_x)
fprintf("FOURS LOOP\n");
n = length(x)-1;
h = (x(length(x)) - x(1))/n;
%h = (x(n_els) - x(1))/n_els
% gather all terms multiplied by 4
fours = 0;
for i = 2:2:length(x)-1
fprintf("i:%d | x(i): %f | f_x: %f | 4*f_x: %f \n",i,x(i),f_x(x(i)),4*f_x(x(i)));
@SergKolo
SergKolo / get_unity_viewports.sh
Created September 30, 2017 16:57
very old script, I wrote better code afterwards. This is kept just for nostalgic purposes
#!/bin/bash
get_screen_geometry()
{
xwininfo -root | awk '/-geometry/{gsub(/+|x/," ");print $2,$3}'
}
SCHEMA="org.compiz.core:/org/compiz/profiles/unity/plugins/core/"
read screen_width screen_depth <<< "$(get_screen_geometry)"
hsize=$(gsettings get $SCHEMA hsize)
@SergKolo
SergKolo / Recurse.java
Created January 24, 2017 00:40 — forked from KazWolfe/Recurse.java
Recursively list directories/files through Java
/*
* Recursively list directories/files through Java, akin to Linux's `ls -R` command.
* (c) 2017, KazWolfe. Under MIT license.
*
* To use, save to `Recurse.java` and compile with `javac Recurse.java`.
* Run with `java -cp . Recurse /path/to/operate/on`. Be sure you are passing in a folder.
*/
import java.io.File;
import java.lang.String;
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Author: Serg Kolo , <1047481448@qq.com>
# Date: December 23, 2016
# Purpose: Indicator that displays timezone
# Written for: http://askubuntu.com/q/863952/295286
# Tested on: Ubuntu 16.04 LTS
#
#!/usr/bin/env python
"""
Author: Serg Kolo <1047481448@qq.com>
Date: Nov 29 , 2016
Purpose:Script for shutting down Ubuntu system
if AC adapter is removed
Written for:http://askubuntu.com/q/844193/295286
"""
import dbus
import time
#!/usr/bin/env python3
# Author: Serg Kolo
# Date: Oct 3rd, 2016
# Description: Script for aligning the center of
# user's active window with the center of the monitor
# Tested on: Ubuntu 16.04
from __future__ import print_function
from gi.repository import Gdk,Gio
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rand_int (int,int);
void copy_array(int *,int *,int);
void merge(int *,int *,int,int,int);
int main()
{
int len = 3;