Skip to content

Instantly share code, notes, and snippets.

View daniel-abramov's full-sized avatar

Daniel Abramov daniel-abramov

  • Munich, Germany
View GitHub Profile
@daniel-abramov
daniel-abramov / update_ver.sh
Created September 15, 2017 15:50
Search and replace the version number based on input parameters to the shell script
#!/bin/sh
# This script will update the specified version for all brands to
# X.Y.Z, where X, Y and Z are input parameters specified by the user.
# Example: `$ sh change_version.sh 1.0.0 2.1.0`
if [ $# -lt 2 ]; then
echo "2 arguments are expected"
exit 1
fi
@daniel-abramov
daniel-abramov / search.sh
Created September 15, 2017 15:48
Search and replace from shell
find . -type f -exec sed -i 's@http://timestamp.verisign.com/scripts/timstamp.dll@http://sha256timestamp.ws.symantec.com/sha256/timestamp@g' {} +
@daniel-abramov
daniel-abramov / config.toml
Created June 8, 2017 16:35
Cargo configuration for crosscompilation for Windows and Mac (~/.cargo/config)
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
rustflags = ["-L/usr/x86_64-w64-mingw32/lib", "-lstatic=ssl", "-lstatic=crypto", "-lgdi32"]
[target.x86_64-apple-darwin]
linker = "/usr/local/osx-ndk-x86/bin/x86_64-apple-darwin15-clang"
rustflags = ["-C", "link-arg=-mmacosx-version-min=10.7"]
@daniel-abramov
daniel-abramov / parse.sh
Created December 30, 2016 17:26
Parse first 5 entries of the ICO format (in case if there are 5 icons) https://en.wikipedia.org/wiki/ICO_(file_format)#Icon_resource_structure
$ hexdump -v -s 6 -e '4/1 "%d \t" "\t\t" 2/2 "%d \t" "\t\t" 2/4 "%d \t"' -e '"\n"' icon.ico | head -n 5
@daniel-abramov
daniel-abramov / enum_windows.rs
Created December 28, 2016 13:56
Convenient Rust wrappers for a couple WinAPI calls
pub fn enumerate_windows<F>(mut callback: F)
where F: FnMut(HWND) -> bool
{
let mut trait_obj: &mut FnMut(HWND) -> bool = &mut callback;
let closure_pointer_pointer: *mut c_void = unsafe { mem::transmute(&mut trait_obj) };
let lparam = closure_pointer_pointer as LPARAM;
unsafe { EnumWindows(Some(enumerate_callback), lparam) };
}
@daniel-abramov
daniel-abramov / fnv.cpp
Created June 19, 2016 16:57
FNV hash for strings
uint64_t fnvhash(const char* data, size_t size) {
uint64_t hsh = 14695981039346656037L;
for (size_t i = 0; i < size; ++i) {
hsh = (hsh * 1099511628211L) ^ (uint64_t)(data[i]);
}
return hsh;
}
// Calculating the hash for QString
template <>
#include <chrono>
#include <iostream>
#include <vector>
#include <QtCore/QVector>
template <typename container>
void test(const char* desc)
{
auto t1 = std::chrono::high_resolution_clock::now();
data Figure = Triangle (Float side)
| Square (Float side)
| Circle (Float radius)
perimeter Triangle side = 3 * side
perimeter Square side = 4 * side
perimeter Circle radius = 2 * pi * radius
#!/usr/bin/python
import cairo
sfc = cairo.PDFSurface( open("file.pdf", "w"), 144, 144 )
cr = cairo.Context(sfc)
cr.set_line_width(1)
cr.set_source_rgb(0.5, 0.5, 0.5)
cr.move_to(10, 10)
#!/usr/bin/python
def generate_permutation(a_count, b_count, c_count, string_length, prefix=""):
if a_count + b_count + c_count == string_length:
print prefix
return
generate_permutation(a_count + 1, b_count, c_count, string_length, "a" + prefix)
generate_permutation(a_count, b_count + 1, c_count, string_length, "b" + prefix)
generate_permutation(a_count, b_count, c_count + 1, string_length, "c" + prefix)