Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@priezz
priezz / 0_reuse_code.js
Last active August 29, 2015 14:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

Keybase proof

I hereby claim:

  • I am priezz on github.
  • I am priezz (https://keybase.io/priezz) on keybase.
  • I have a public key whose fingerprint is 41D7 12FC 55EF 7EE0 F184 297D 749F 0E88 1E2F F8B7

To claim this, I am signing this object:

@priezz
priezz / crc32.ts
Last active December 26, 2017 17:44
Firestore client for Admin-on-rest
function crc32(str: string) {
let crc = -1
for(let i = 0; i < str.length; i++) {
crc = (crc >>> 8) ^ crc32.bTable[(crc ^ str.charCodeAt(i)) & 0xFF]
}
return (crc ^ (-1)) >>> 0
}
crc32.aTable = '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E
{
"compilerOptions": {
"allowJs": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"baseUrl": ".",
"charset": "utf-8",
"checkJs": true,
@priezz
priezz / objects.ts
Created June 20, 2019 05:22
Fields manipulation
// TODO:Publish to npm and use as a common dependency
Object.defineProperty(Object.prototype, 'renameProperty', {
configurable: false, // Cannot be deleted via the delete operator
enumerable: false, // Will not show up in a for-in loop.
writable: false, // Cannot alter this property
value(oldName: string, newName: string) {
if(oldName === newName) return this
this[newName] = this[oldName]
delete this[oldName]
@priezz
priezz / weeks.ts
Created June 20, 2019 05:24
Week number calculation
/* For a given date, get the ISO week number.
Algorithm is to find nearest Thursday, it's year is the year of the week number.
Then get weeks between that date and the first day of that year.
NOTE: Dates in one year can be weeks of previous or next year, overlap is up to 3 days.
e.g. 2014/12/29 is Monday in week 1 of 2015, 2012/1/1 is Sunday in week 52 of 2011
*/
export function getWeekNumber(d: Date) {
// Copy date so don't modify original
d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate()))
// Set to nearest Thursday: current date + 4 - current day number
@priezz
priezz / compare.ts
Created June 20, 2019 05:25
Objects equality deep checking
export function objectsEqual(...objects: any[]) {
let leftChain: any[]
let rightChain: any[]
const _compareTwoObjects = (x: any, y: any) => {
// Remember that NaN === NaN returns false and isNaN(undefined) returns true
if(isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') return true
// Compare primitives and functions. Check if both arguments link to the same object.
// Especially useful on the step where we compare prototypes
if(x === y) return true
@priezz
priezz / main.dart
Last active January 8, 2020 14:14
Find all the bugs
/// The code below has no syntax errors and is compiled
///
/// Detect and fix all logical and runtime errors.
/// Please try to keep naming and structure
void main() {
final List<double> values = [1, 2.5, 3, 4.5, 5, 6.5, 7];
final int itemsCount = values.length;
values.add(8.5);
@priezz
priezz / main.dart
Last active December 20, 2022 17:29
Typed data classes
import 'package:data_classes/data_classes.dart';
import 'package:common/const.dart';
part 'change_log.g.dart';
typedef FieldValueGetter<T> = T Function(dynamic);
enum EntityType {
series,