Skip to content

Instantly share code, notes, and snippets.

View DC3's full-sized avatar

Dee Cheung DC3

View GitHub Profile
@DC3
DC3 / React Native.md
Created November 26, 2023 07:37 — forked from insertish/React Native.md
Configure React Native with Typescript, Vite.js for react-native-web and Storybook.
@DC3
DC3 / cookies.js
Last active October 19, 2023 06:25
Bun + js decrypt chromium sqlite cookie
// TODO v11 v12
import { Database } from 'bun:sqlite'
import { createDecipheriv, pbkdf2Sync } from 'node:crypto'
const KEY_LENGTH = 16
const SALT = 'saltysalt'
const IV = Buffer.alloc(KEY_LENGTH).fill(' ')
const password = 'peanuts'
const key = getDerivedKey(password, 1)
/**
* Format a date like YYYY-MM-DD.
*
* @param {string} template
* @param {Date=} [date]
* @return {string}
* @license MIT
*/
function formatDate(template, date) {
var specs = 'YYYY:MM:DD:HH:mm:ss'.split(':');
@DC3
DC3 / curl-crawler.sh
Created November 4, 2021 22:32 — forked from oliveratgithub/curl-crawler.sh
Unix Shell-Script to crawl a list of website URLs using curl
#!/bin/sh
timezone="Europe/Zurich"
# List of valid timezones: wikipedia.org/wiki/List_of_tz_database_time_zones
script="${0##*/}"
rootdir=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
logfile="$script.log"
log="$rootdir/$logfile"
now=$(TZ=":$timezone" date)
# Uncomment 'mailto=' (remove #) to enable emailing the log upon completion
#mailto="your@email.com"
@DC3
DC3 / browser_history.md
Created June 30, 2020 08:01 — forked from dropmeaword/browser_history.md
Playing around with Chrome's history

Browser histories

Unless you are using Safari on OSX, most browsers will have some kind of free plugin that you can use to export the browser's history. So that's probably the easiest way. The harder way, which seems to be what Safari wants is a bit more hacky but it will also work for other browsers. Turns out that most of them, including Safari, have their history saved in some kind of sqlite database file somewhere in your home directory.

The OSX Finder cheats a little bit and doesn't show us all the files that actually exist on our drive. It tries to protect us from ourselves by hiding some system and application-specific files. You can work around this by either using the terminal (my preferred method) or by using the Cmd+Shft+G in Finder.

Finder

Once you locate the file containing the browser's history, copy it to make a backup just in case we screw up.

@DC3
DC3 / id.coffee
Created June 22, 2020 09:42 — forked from zhuangya/id.coffee
ID card verify
verify = (idcard) ->
factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
mask = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
idcard[idcard.length - 1] is mask[((x * factor[i] for x, i in idcard[0...idcard.length - 1]).reduce (x, y) -> x + y) % mask.length].toString()
const resolved = Promise.resolve();
class Deferred {
constructor() {
const p = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
this.then = p.then.bind(p);
@DC3
DC3 / debounceHOC.js
Last active November 27, 2017 18:30
React controlled component debounce HOC
// usage
// debounceHOC('input', { onChange: 300, onMouseOver: 1e3})
import _ from 'lodash';
import React, {PureComponent} from 'react';
import {findDOMNode} from 'react-dom';
function debounceHOC(Comp, events = {}) {
class debounceEventsComponent extends PureComponent {
constructor(props) {
@DC3
DC3 / extend-array.js
Created September 18, 2017 03:36 — forked from Gozala/extend-array.js
Array subclass ES5
// No need to sub class Array if what you need is just an extended
// array. Example below illustrates the way to extend Array.
function SubArray() {
return Object.defineProperties(Array.prototype.slice.call(arguments), SubArrayDescriptor)
}
SubArray.prototype = Array.prototype
var SubArrayDescriptor =
{ constructor: { value: SubArray }
, last: { value: function last() {
@DC3
DC3 / test-get-all-pixel-hex.coffee
Created August 31, 2017 10:14
test-get-all-pixel-hex.coffee
testImgUrl = '//img.alicdn.com/tps/i4/TB1PVZoOpXXXXcKXXXXSutbFXXX.jpg'
rgbToHex = (r, g, b) ->
hex = (i) ->
h = i.toString 16
h = '0' + h if h.length < 2
h
['#', hex(r), hex(g), hex(b)].join('')
getOnePixelHex = (context, x, y, w = 1, h = 1) ->