J

@jogomu

closest midnight

Java
1 year ago
import java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; import java.time.ZonedDateTime; public class Main { public static long findClosestMidnight(long microsecondsSinceEpoch, String timeZone) { // Convert microseconds to milliseconds long millisecondsSinceEpoch = microsecondsSinceEpoch / 1000;

midfreq compression

Python
1 year ago
import numpy as np import scipy.fftpack import zlib # Generate a sample sequence of elapsed time (in nanoseconds) #sequence = np.random.randint(1, 1000, size=1000) # Example sequence #sequence = [0,0,0,0,50000,35000,40000,20000,35000,300,400,200,400,500,300,200,0,0,0] sequence=[5000,4000,5500,4500,3000,4000, 5000,4000,5500,4500,3000,4000, 5000,4000,5500,4500,3000,4000,

dct

Python
1 year ago
import json from scipy import fft data=[1000,800,3000,50000,23,56,795] x=list(fft.dct(data)) print(json.dumps(x,indent=4)) out=list(fft.idct(x)) print(json.dumps(out,indent=4))

atomic printer - minimal syntax

C++
2 years ago
#include <cstdarg> #include <cstdio> #include <string> #include <unistd.h> #include <cassert> class aprintf_class { public:

atomic printer

C++
2 years ago
#include <cstdarg> #include <cstdio> #include <string> #include <unistd.h> class PrintContext { public: ~PrintContext() {

assert with helpful message

C++
2 years ago
#include <iostream> #include <cassert> int main() { assert(0); // assert(0 && "oops this failed"); return 0; }

pointers to first elements are pointers to arrays

C++
2 years ago
#include <iostream> int main() { int a[10] = {1,2,3,4,5,6,7,8,9,10}; int *b = a; int *c = &b[0]; printf("%d\n",a[2]); printf("%d\n",b[2]);

cin

C++
2 years ago
#include <iostream> int main() { int num; std::cin >> num; printf("%d\n",num); std::cin >> num; printf("%d\n",num); std::cin >> num; printf("%d\n",num);

varargs

C++
2 years ago
#include <iostream> #include <cstdarg> void my_printf(const char* format, ...) { va_list args; va_start(args, format); vprintf(format, args); // Call vprintf with variable arguments va_end(args);

fork/exec

C++
2 years ago
#include <cstdio> #include <unistd.h> #include <sstream> #include <vector> #include <cerrno> #include <cstring> #include <sys/wait.h> int main(int argc, char *argv[]) {

efficient symbol-then-tag-value cache

C++
2 years ago
#include <vector> #include <map> #include <string> #include <list> #include <charconv> #include <cstring> template <typename T> class resizing_vector : public std::vector<T> { public:

troy ascii art

C
2 years ago
#include <stdio.h> #include <stdlib.h> #include <math.h> /* - Troy Muehlhausen - tjmuehlh - This program reads a text file and reads its content, converting that content - into generated "ASCII Art." It is capable of executing point, rectangle, line, - and fill commands.

std::copy from deque to array

C++
2 years ago
#include <iostream> #include <deque> #include <sys/uio.h> #include <cassert> #include <cstring> void fill(std::deque<iovec> &d) { for(uint64_t i=0; i<1024; i++) {

loop logic

C++
2 years ago
#include <iostream> int main() { int64_t totlen = 9417; for(int i=0; totlen>0; i+=1472) { auto len = (totlen>1472) ? 1472 : totlen; std::cout << "copy " << len << " bytes from " << i << " (first byte not accessed: " << (i+len) << ")" << std::endl; totlen-=1472; }

select deques by vector map

C++
2 years ago
#include <iostream> #include <vector> #include <map> #include <cstdio> #include <sstream> #include <deque> struct CSelection : public std::vector<std::deque<int> *> { size_t size()

map keys are vectors

C++
2 years ago
#include <iostream> #include <vector> #include <map> #include <cstdio> #include <sstream> int main() { std::map< std::vector<std::string>, int> m; m[{"hello","world"}]=1; m[{"momma"}]=2;

get certain parts of set of paths

C++
3 years ago
#include <iostream> #include <set> #include <cassert> std::set<std::string, std::less<> > extract_prefix(const std::set<std::string, std::less<> > &all, const std::string_view &prefix) { assert( prefix[prefix.size()-1] == '/'); // replace / with next ascii char higher std::string upper { prefix.substr(0,prefix.size()-1) }; upper += std::string(1, prefix[prefix.size()-1] + 1);

search iovecs

C++
3 years ago
#include <cstdio> #include <sys/uio.h> #include <utility> #include <cassert> #include <deque> template<typename T> struct ArrayWrapper { ArrayWrapper(const T *_ptr, size_t _cnt) : ptr(_ptr), cnt(_cnt) {}

turkey

Java
3 years ago
import java.util.*; import java.lang.*; import java.io.*; // The main method must be in a class named "Main". class Main { static boolean fn(String str) { if(str=="turkey" || str=="TURKEY") return true;

split(py)

Python
3 years ago
pathstr='/bin:/usr/bin:/usr/local/bin' paths=pathstr.split(':') for path in paths: print(path)