Skip to content

Instantly share code, notes, and snippets.

View kimwalisch's full-sized avatar

Kim Walisch kimwalisch

  • Luxembourg
  • 03:39 (UTC +01:00)
View GitHub Profile
@kimwalisch
kimwalisch / wget_list_of_urls
Created January 10, 2014 18:59
Download list of files from terminal using wget
wget --content-disposition -i urls.txt
@kimwalisch
kimwalisch / find_files_by_keyword
Last active August 29, 2015 13:57
Find all files that contain a user specified keyword (UNix)
# Find all files KEYWORD
$ fgrep -R --files-with-matches KEYWORD .
# Find all files with FILENAME and KEYWORD
$ find . -name FILENAME -exec fgrep --files-with-matches KEYWORD {} \;
@kimwalisch
kimwalisch / oracle_sql_commands.sql
Last active August 29, 2015 14:00
oracle_sql_commands
-- Seach column name in database
select table_name from all_tab_columns where column_name like '%COLUMN_NAME%';
-- Seach table name in database
select table_name from all_tables where table_name like '%TABLE_NAME%';
// Author: Kim Walisch
// Released into public domain
#include <windows.h>
#include <cstdlib>
typedef BOOL (WINAPI *LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
/// Get the CPU's cache size in bytes.
/// Works on Windows (MSVC, Intel C++ Compiler, Cygwin, ...).
@kimwalisch
kimwalisch / constexpr_sqrt.cpp
Last active August 29, 2015 14:12
Compile time square root using C++11 constexpr
///
/// @file constexpr_sqrt.cpp
/// @brief Calculate integer square roots at compile time using
/// C++11 constexpr.
/// @author Kim Walisch, <[email protected]>
/// @license Public Domain
#include <iostream>
#include <cassert>
#include <cmath>
@kimwalisch
kimwalisch / segmented_sieve.cpp
Last active July 31, 2020 08:33
Simple segmented sieve of Eratosthenes implementation
/// @file segmented_sieve.cpp
/// @author Kim Walisch, <[email protected]>
/// @brief This is a simple implementation of the segmented sieve of
/// Eratosthenes with a few optimizations. It generates the
/// primes below 10^9 in 0.8 seconds (single-threaded) on an
/// Intel Core i7-6700 3.4 GHz CPU.
/// @license Public domain.
#include <iostream>
#include <algorithm>
@kimwalisch
kimwalisch / l1d_cache_size.cpp
Last active November 2, 2022 00:27
Get L1 data cache size on most operating systems
///
/// @file l1d_cache_size.cpp
/// @brief Get the L1 cache size in kilobytes on Windows
/// and most Unix-like operating systems.
///
/// Copyright (C) 2015 Kim Walisch, <[email protected]>
///
/// This file is distributed under the BSD License.
///
@kimwalisch
kimwalisch / primes.cpp
Last active August 14, 2017 09:01
Generate primes using the primesieve C++ library
#include <primesieve.hpp>
#include <iostream>
int main()
{
primesieve::iterator it;
uint64_t prime = it.next_prime();
// iterate over the primes below 10^6
for (; prime < 1000000; prime = it.next_prime())
@kimwalisch
kimwalisch / sieving_loop.asm
Created November 9, 2015 21:01
primesieve inner sieving loop
; primesieve inner sieving loop
; Uses only 11 instructions (x86-64) to cross-off the next 8 multiples
.L99:
andb $-3, (%rax)
andb $-9, (%rax,%r14)
andb $127, (%rax,%r12)
andb $-33, (%rax,%rbp)
andb $-2, (%rax,%r10)
andb $-65, (%rax,%rbx)
andb $-5, (%rax,%r9)
struct libdivide_u64_t libdivide_u64_gen(uint64_t d) {
struct libdivide_u64_t result;
const uint32_t floor_log_2_d = 63 - libdivide__count_leading_zeros64(d);
uint64_t proposed_m, rem;
uint8_t more;
proposed_m = libdivide_128_div_64_to_64(1ULL << floor_log_2_d, 0, d, &rem); //== (1 << (64 + floor_log_2_d)) / d
LIBDIVIDE_ASSERT(rem > 0 && rem < d);