Skip to content

Instantly share code, notes, and snippets.

@ckybonist
ckybonist / git-find-file-deletion-commit.sh
Created July 11, 2022 11:37
Find the commit of file deletion
git log --full-history --name-status --diff-filter=D -- <file-path>
@ckybonist
ckybonist / ruby-vscode-settings.json
Created December 21, 2021 03:43
Ruby linter and Intellesense config for VSCode
{
"ruby.locate": {
"include": "**/*.rb"
},
"ruby.useBundler": true,
"ruby.codeCompletion": "rcodetools",
"ruby.interpreter.commandPath": "~/.asdf/shims/irb",
"ruby.lintDebounceTime": 500,
"ruby.lint": {
"ruby": true,
@ckybonist
ckybonist / rspec_helper.rb
Created August 24, 2021 17:27 — forked from mlanett/rspec_helper.rb
Helper to clear redis before/after examples in rspec.
=begin
Include in your rspec config like so:
RSpec.configure do |spec|
spec.include RSpec::RedisHelper, redis: true
end
This helper will clean redis around each example.
=end
@ckybonist
ckybonist / devise_login_rails_console.rb
Last active August 23, 2021 08:42 — forked from seabre/devise_login_rails_console.rb
Devise Login Through Rails Console
ApplicationController.allow_forgery_protection = false
app.post('/sign_in_path',
{ ':user_model': { 'email': 'users@email.com', 'password': 'plain_text_password' } })
@ckybonist
ckybonist / py-arr-ans.py
Created March 4, 2021 07:35
Question from my friend
#!/usr/bin/env python3
items = range(1, 100)
# 1
for (index, value) in enumerate(items):
if index == 1 or index == 21 or index == 41:
print("Do something only at:", index)
print()
@ckybonist
ckybonist / ff-prevent-invalid-state-error.js
Last active November 2, 2020 07:34
Prevent old Firefox (e.g. 54.0) throw InvalidStateError by default in private mode
function debug(showError = true) {
if (window.indexedDB) {
try {
const request = window.indexedDB.open('demo', 1);
request.onsuccess = function (event) {
// not raised
};
request.onupgradeneeded = function (event) {
// not raised
};
@ckybonist
ckybonist / .babelrc
Last active August 20, 2019 16:42
Babel 7 config
{
"presets": [["@babel/preset-env"], "@babel/preset-react"],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"corejs": 3,
"proposals": true
}
],
@ckybonist
ckybonist / packages.json
Created August 20, 2019 16:37
Dependencies for babel 7 (with core-js-3 support) and webpack and react
{
"name": "ILoveFatCat",
"version": "1.0.0",
"description": "",
"main": "index.js",
"browserslist": [
"defaults"
],
"scripts": {
"start": "webpack-dev-server --open --hot --mode development",
// 假設你是要一到某個 node 到另一個 node "之後"
function moveElementInSelect(parentId, srcIndex, destIndex) {
const parent = document.getElementById(parentId);
const nodeList = parent.children;
const src = nodeList.item(srcIndex);
const dest = nodeList.item(destIndex + 1);
// 將 src element 直接搬到 dest 之前
parent.insertBefore(src, dest);
}
@ckybonist
ckybonist / react-hooks.js
Created July 13, 2019 11:04
React Hooks
const React = (function() {
let hooks = [];
let idx = 0;
function useState(initValue) {
const state = hooks[idx] || initValue;
const _idx = idx;
const setState = newValue => {
hooks[_idx] = newValue;