Skip to content

Instantly share code, notes, and snippets.

View JIghtuse's full-sized avatar

Boris Egorov JIghtuse

View GitHub Profile
me:
@true
a:
@true
sandwich:
@[ "$$(id -u)" -eq 0 ] && echo "Okay." || echo "What? Make it yourself."
.PHONY: me a sandwich
@JIghtuse
JIghtuse / fizzbuzz.hs
Last active August 29, 2015 14:02
Haskell FizzBuzz
module Main where
fizzBuzz :: Int -> String
fizzBuzz n
| mod n 15 == 0 = "FizzBuzz"
| mod n 3 == 0 = "Fizz"
| mod n 5 == 0 = "Buzz"
| otherwise = show n
main = do
@JIghtuse
JIghtuse / undead.cpp
Created September 24, 2014 17:41
Undead
class Undead {
~Undead()=delete;
};
@JIghtuse
JIghtuse / scanf
Created November 11, 2014 03:59
%m length specifier allocates as many memory as needed to place input
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef __GLIBC__
#if !(__GLIBC_PREREQ(2, 7))
#error %m is not available
#endif
@JIghtuse
JIghtuse / network.sh
Created May 11, 2015 08:11
bash-tricks
#!/bin/sh
# get all ipv4 addresses of existing connections
ip -4 -oneline a | awk '{ print $2 ": " $4 }'
@JIghtuse
JIghtuse / gist:7340984e80d49f1d4935
Created September 29, 2015 11:09 — forked from jayjanssen/gist:5697813
Testing multicast with iperf
this is a sample of output:
root@percona-db-2:~# iperf -s -u -B 226.94.1.1 -i 1
------------------------------------------------------------
Server listening on UDP port 5001
Binding to local address 226.94.1.1
Joining multicast group 226.94.1.1
Receiving 1470 byte datagrams
UDP buffer size: 122 KByte (default)
------------------------------------------------------------
@JIghtuse
JIghtuse / playground.rs
Created October 6, 2015 07:35 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::str::FromStr;
#[derive(Debug)]
enum Version { Version1, Version2 }
#[derive(Debug)]
enum ParseError { InvalidSyntax, UnsupportedVersion }
fn parse_version(line: String) -> Result<Version, ParseError> {
let mut split = line.split("=");
@JIghtuse
JIghtuse / playground.rs
Created October 6, 2015 08:12 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::str::FromStr;
#[derive(Debug)]
enum Version { Version1, Version2 }
#[derive(Debug)]
enum ParseError { InvalidSyntax, UnsupportedVersion }
struct NameValue {
name: String,
@JIghtuse
JIghtuse / DigitCounter.java
Created October 21, 2015 13:41
Horrible digit counting Java class
class DigitCounter {
public static int getCountsOfDigits(int n)
{
if (n > 999999999)
return 10;
if (n > 99999999)
return 9;
if (n > 9999999)
return 8;
if (n > 999999)
@JIghtuse
JIghtuse / unlikely.c
Created October 22, 2015 09:34
unlikely.c
#include <stdlib.h>
#define unlikely_custom(p) (!!(p))
char* f() {
char *ppsz_ret;
ppsz_ret = malloc(sizeof(char *) * 12);
if (! ! (!ppsz_ret))
return NULL;