Skip to content

Instantly share code, notes, and snippets.

View littlefuntik's full-sized avatar

Hryhorii Furletov littlefuntik

View GitHub Profile
@littlefuntik
littlefuntik / 3d-engine.c
Last active December 4, 2020 10:20
Read habr post and write code example habr.com/ru/post/334580/
// clang -o program program.c $(sdl2-config --cflags --libs) && ls -lah && ./program
#include <SDL2/SDL.h>
#include <stdlib.h>
#include <time.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int LIGHT_TYPE_POINT = 1;
@littlefuntik
littlefuntik / timeouts.go
Last active July 9, 2023 05:43
Go lang request timeouts example, DialContext, context.WithTimeout, http.Client, http.NewRequestWithContext
package main
import (
"context"
"io/ioutil"
"log"
"net"
"net/http"
"time"
)
@littlefuntik
littlefuntik / main.go
Created March 11, 2020 13:06
Go iterations
package main
import "fmt"
func main() {
var funcs1 []func()
var funcs2 []func()
for _, v := range []string{"create", "update", "delete"} {
fmt.Println(v, &v)
@littlefuntik
littlefuntik / .Xresources
Created January 2, 2020 15:46
urxvt, perl, hotkeys, clipboard / xfce, dark
! do not scroll with output
URxvt*scrollTtyOutput: false
! scroll in relation to buffer (with mouse scroll or Shift+Page Up)
URxvt*scrollWithBuffer: true
! scroll back to the bottom on keypress
URxvt*scrollTtyKeypress: true
#!/bin/sh
# utils / helpers
CSRF() {
printf '%s' "$(tr -dc '0-9a-z' </dev/urandom | head -c3)"
}
RANDOM_EMAIL() {
printf '%d%s@example.com' "$(date +%s)" "$(tr -dc '[:lower:]' </dev/urandom | head -c8)"
@littlefuntik
littlefuntik / graphql-handle-request.go
Last active September 4, 2019 12:04
go-micro req server.Request and response
import (
"strings"
"bytes"
"strconv"
"context"
"encoding/json"
api "github.com/micro/go-api/proto"
)
type GraphqlOperation struct {
@littlefuntik
littlefuntik / main.h
Created May 7, 2019 14:27
Web server example written on C language (Mac OS)
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
// global constants
#define PORT 8080 // port to connect on
@littlefuntik
littlefuntik / psmem.sh
Last active March 14, 2023 23:47
Ubuntu/Linux get process memory usage(include child processes)
#!/bin/sh
pmap -x $(ps -fC "$1" | head -n2 | tail -n1 | awk '{print $2}') | tail -n 1 | awk '{print $3/1024 "MB"}'
# example usage:
#
# $ psmem chrome
# 1144.3MB
@littlefuntik
littlefuntik / get-docker-nat-ip.md
Last active April 16, 2019 05:49
Get DockerNAT IP address.

Linux or MacOS:

export SERVER = 'localhost'

Windows (PowerShell)

$Server = (Get-NetIPAddress -InterfaceAlias *docker* -AddressFamily IPv4).IPAddress
@littlefuntik
littlefuntik / add-filename-prefix.php
Created April 3, 2019 18:00
Add filename prefix. "/a/b/c/abc.jpg" to "/a/b/c/abc-thumb.jpg"
<?php
$path = '/a/b/c/abc.jpg';
$path_new = substr( $path, 0, strrpos( $path, '.' ) ) . '-thumb' . substr( $path, strrpos( $path, '.' ) );
var_export( $path_new );
// Output: /a/b/c/abc-thumb.jpg