Skip to content

Instantly share code, notes, and snippets.

@Freditansari
Freditansari / index.html
Created September 6, 2025 05:25
chart js candlestick working example.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Minimal Candlestick – chartjs-chart-financial</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body { font-family: system-ui, Arial; background:#111; color:#eee; margin:0; padding:16px; }
.toolbar { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-bottom:12px; }
.toolbar select, .toolbar button { padding:6px 8px; border-radius:6px; border:1px solid #333; background:#1b1b1b; color:#eee; }
@Freditansari
Freditansari / example.html.erb
Created September 22, 2023 07:50
this is how to do table in scaffolded RoR projects
<h1> My blog</h1>
<% @blog_posts.each do |blog_post| %>
<h2><%= link_to blog_post.title, "/blog_post/#{blog_post.id}" %></h2>
<%= blog_post.body %>
<% end %>
@Freditansari
Freditansari / object-full-text-search.js
Last active June 29, 2022 14:22
full text search for every object thrown at it. It returns index of arrays where the item located.
let data=[
{productName: "banana", price: 100, qty: 2, subtotal: 200, date: new Date(2023, 1, 24) },
{productName: "dragon fruit", price: 150, qty: 1, subtotal: 150 , date: new Date(2012, 1, 26) },
{productName: "screwdriver", price: 10, qty: 1, subtotal: 10.10, date: new Date(2020, 11, 16)},
{productName: "potato", price: 18, qty: 1, subtotal: 18, date: new Date(2020, 11, 16)},
]
function textSearch(searchTerm){
let result =[]
let counter =0
@Freditansari
Freditansari / example.py
Created December 3, 2021 07:13
to find a key in a json string in python
# data sample
# "{\"order_summary\": [
# {\"total_invoice\": 85000}, {\"expire_date\": \"2022-12-03T13:55:15.771771\"}, {\"estate_id\": 2}],
# \"order_details\": [
# {\"service\": \"12 Months ads\", \"amount\": 75000},
# {\"service\": \"Premium ads\", \"amount\": 10000}
# ]}"
order = Orders.query.filter_by(id=25).first()
@Freditansari
Freditansari / desreialize_datetime_from_json.py
Created December 2, 2021 08:09
How to deserialize datetime from json
from datetime import datetime
date_string = "2022-05-31T15:02:48.575980"
converted_date = datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S.%f')
print(converted_date)
@Freditansari
Freditansari / almebic_enum_example.py
Created November 22, 2021 13:26
example on how to create alembic enum
"""added estate type
Revision ID: ae9471a33d22
Revises: 98b6e4b854f6
Create Date: 2021-11-22 18:19:51.413477
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
@Freditansari
Freditansari / bokeh-flask.py
Created July 19, 2021 00:59
bokeh example on flask
import flask_bcrypt
from bokeh.models import HoverTool
from flask import Blueprint, render_template, request, redirect, url_for
from app import db
from sqlalchemy.sql import text
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.resources import INLINE
@Freditansari
Freditansari / array_splice.js
Last active December 7, 2020 04:39
move column order from first to second column
const columnsFromBackend =
{
[uuid()]:{
name:'Todo',
items : [
{id: uuid(), content:'first task'},
]
},
[uuid()]:{
name:'In Progress',
@Freditansari
Freditansari / gist:6f51e5a00aad747aac71c438d3cb853c
Created October 9, 2020 16:12
Simple lunr getting started
const lunrjs = require("lunr")
var documents = [
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},