Skip to content

Instantly share code, notes, and snippets.

View JIghtuse's full-sized avatar

Boris Egorov JIghtuse

View GitHub Profile
@JIghtuse
JIghtuse / swap.cpp
Created September 30, 2015 07:26
traps
// Example from Bjarne Stroustrup's Programming
#include <iostream>
using namespace std;
void swap_v(int a, int b)
{ int temp; temp = a, a = b; b = temp; }
void swap_r(int& a, int& b)
{ int temp; temp = a, a = b; b = temp; }
@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;
@JIghtuse
JIghtuse / autogen.sh
Created October 22, 2015 15:20
wayland autogen.sh
#! /bin/sh
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.
(
cd "$srcdir" &&
autoreconf --force -v --install
) || exit
test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"
@JIghtuse
JIghtuse / pull_apk.sh
Created November 11, 2015 08:54
APK pulling
# http://codetheory.in/get-application-apk-file-from-android-device-to-your-computer/
adb shell pm list packages
# Output:
# package:org.coursera.android
# package:com.quizup.core
# package:com.airbnb.android
adb shell pm path com.airbnb.android
# Output:
@JIghtuse
JIghtuse / wct_compiler.sh
Created November 25, 2015 04:57
"wct" "compiler"
#!/bin/sh
source=$1
if [ -z $source ]; then
echo "usage: $0 filename.wct > filename.bin"
exit 1
fi
cat "$source" | tr ABCDEFGHIJKLMNPO 0123456789abcdef | xxd -r -p
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;
fn get_dimensions(line: String) -> Vec<i32> {
line.split('x').map(|x| x.parse::<i32>().unwrap()).collect::<Vec<i32>>()
}
fn how_many_paper() -> i32 {
let f = File::open("input").unwrap();
@JIghtuse
JIghtuse / solver.cxx
Created December 10, 2015 08:31
Dependency solver using std::future, std::promise, std::async
#include <iostream>
#include <future>
#include <map>
using namespace std;
template <class T>
struct problem {
promise<shared_future<T> > p;
shared_future<shared_future<T> > f;