Skip to content

Instantly share code, notes, and snippets.

View pharzan's full-sized avatar

Farzan pharzan

View GitHub Profile
@dannguyen
dannguyen / schemacrawler-sqlite-macos-howto.md
Last active June 30, 2024 18:52
How to use schemacrawler to generate schema diagrams for SQLite from the commandline (Mac OS)
@xen
xen / check_hash.py
Last active May 3, 2024 21:19
telegram site auth
# implementation of Telegram site authorization checking algorithm
# for more information https://core.telegram.org/widgets/login#checking-authorization
import collections
import hmac
import hashlib
def check_string(d, token):
secret = hashlib.sha256()
secret.update(token.encode('utf-8'))
@NigelEarle
NigelEarle / Knex-Migrations-Seeding.md
Last active June 19, 2024 14:20
Migration and seeding instructions using Knex.js!

Migrations & Seeding

What are migrations??

Migrations are a way to make database changes or updates, like creating or dropping tables, as well as updating a table with new columns with constraints via generated scripts. We can build these scripts via the command line using knex command line tool.

To learn more about migrations, check out this article on the different types of database migrations!

Creating/Dropping Tables

@javilobo8
javilobo8 / download-file.js
Last active July 27, 2024 07:41
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@soruly
soruly / compre.py
Last active June 15, 2023 14:38
Compare two images using OpenCV and SIFT in python
import cv2
import sys
import os.path
import numpy as np
def drawMatches(img1, kp1, img2, kp2, matches):
rows1 = img1.shape[0]
cols1 = img1.shape[1]
rows2 = img2.shape[0]
@cjdd3b
cjdd3b / cluster.py
Last active July 27, 2023 08:16
Example of perceptual hashing for near-duplicate image detection
'''
cluster.py
Uses the Hamming distance between perceptual hashes to surface near-duplicate
images.
To install and run:
1. pip install imagehash
2. Put some .dat files in a folder someplace (script assumes ./data/imgs/*.dat)
@webcss
webcss / defineDOM.js
Last active September 28, 2015 12:27
m.dom.<Tag/Component>
var HTMLTags = ['A', 'DIV', 'SECTION', 'HEADER', 'FOOTER', 'P',....];
m.dom = {};
m.defineDOM = function defineDOM(elementName, component, conf) {
// register a html tag, no special component view given
if (!component) {
elementName = elementName.toLowerCase();
m.dom[elementName] = function(attrs, children) {
return m(elementName, attrs, children);
@ebraminio
ebraminio / gist:5292017
Last active July 27, 2024 05:49
Check Iranian National Code Validity - بررسی صحت کد ملی ایرانی - Clojure, C#, F#, Ruby, JavaScript, Dart, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir, PowerQuery M Language, VBA, R, Lua, Fortran, Pascal/Delphi, Excel, Stored Procedure / MySQL
// Check Iranian National Code Validity - Clojure, C#, F#, Ruby, JavaScript, Dart, Python, Scala, Java 8, PHP, C, Go, Swift, Kotlin, Groovy, Rust, Haskell, Erlang, Elixir, Power Query M Language, VBA, R, Lua, Fortran, Pascal/Delphi, Excel, Stored Procedure / MySQL
// بررسی صحت کد ملی ایران - کلوژر، سی‌شارپ، اف‌شارپ، روبی، جاوااسکریپت، دارت، پایتون، اسکالا، جاوا ۸، پی‌اچ‌پی، سی، گو، سوئیفت، کاتلین، گرووی، راست، هسکل، ارلنگ، الکسیر، پاورکوئری ام، وی‌بی ای، آر، لوآ، فرترن، پاسکال/دلفی، اکسل، مای‌اس‌کیوال
// در نسخه‌های قبل یکسان بودن اعداد نا معتبر تشخیص داده می‌شد ولی
// اعداد یکسان نامعتبر نیست https://web.archive.org/web/20170706081048/http://www.fardanews.com/fa/news/127747/رندترین-شماره-ملی-بلای-جان-صاحبش-شد
// بعضی از پیاده‌سازی‌ها سریع نیستند، می‌توانید نسخهٔ خود را بر پایهٔ
// نسخهٔ سی یا گو ایجاد کنید که بهترین سرعت را داشته باشد
/**
@atree
atree / redis-hash-loop.js
Created January 17, 2013 16:30
Node JS - Iterating over redis keys, grabbing value from hash for view.
exports.list = function(req, res) {
var return_dataset = [];
client.keys('*', function(err, log_list) {
var multi = client.multi();
var keys = Object.keys(log_list);
var i = 0;
keys.forEach(function (l) {
client.hget(log_list[l], "modified_at", function(e, o) {