Skip to content

Instantly share code, notes, and snippets.

@deepakmahakale
deepakmahakale / Bookmarklet.md
Created April 18, 2024 07:38
Turn relative time to actual time strings on GitHub

Add new Bookmark

Screenshot 2024-04-18 at 13 02 23

Add the code in URL Input

javascript: (() => { Array.from(document.getElementsByTagName("relative-time")).forEach((d) => d.shadowRoot.textContent = d.title) })();
@deepakmahakale
deepakmahakale / toggle_scroll.sh
Created October 18, 2022 17:32
Bash Script | Apple Script to toggle scroll direction
#!/bin/bash
osascript <<EOD
tell application "System Preferences"
(run)
set current pane to pane "com.apple.preference.trackpad"
end tell
tell application "System Events"
tell process "System Preferences"
delay 0.6
click radio button "Scroll & Zoom" of tab group 1 of window "Trackpad"
@deepakmahakale
deepakmahakale / links.md
Last active July 6, 2020 06:32
List of sites / tools I normally use
@deepakmahakale
deepakmahakale / crontab.sh
Created December 2, 2019 09:17
A script to restart a node js app and serve over localtunnel (including crontab)
# m h dom mon dow command
* * * * * /home/deepak/workspace/status_check.sh >> /home/deepak/workspace/logs/status.log 2>&1
@deepakmahakale
deepakmahakale / speech_ai.js
Created August 21, 2019 07:10
A twilio function used for NLU
/**
* Hindi Voice Bot
*
* This function lets you ask questions in Hindi and get a proper response
*/
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse()
if(event.SpeechResult) {
var got = require('got');
var requestPayload = {
# app/models/user.rb
class User < ActiveRecord::Base
has_many :posts, dependent: :destroy
has_many :published_posts, -> { published }, class_name: 'Post'
end
# app/models/post.rb
class Post < ActiveRecord::Base
belongs_to :user
scope :published, -> { where(published: true) }
User.includes(:published_posts).map do |user|
[user.name, user.published_posts.map(&:title).join(', ')]
end
User Load (0.3ms) SELECT "users".* FROM "users"
Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE (published = 't') AND "posts"."user_id" IN (1, 2, 3)
#=> [["Jack", "post-1, post-2"], ["Adam", "post-3, post-3"], ["John", "post-5, post-6"]]
# app/models/user.rb
class User < ActiveRecord::Base
has_many :posts, dependent: :destroy
has_many :published_posts, -> { where(published: true) }, class_name: 'Post'
end
# app/models/post.rb
class Post < ActiveRecord::Base
belongs_to :user
scope :published, -> { where(published: true) }
User.includes(:posts).map do |user|
[user.name, user.posts.published.map(&:title).join(', ')]
end
User Load (0.2ms) SELECT "users".* FROM "users"
Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE "posts"."user_id" IN (1, 2, 3)
Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."user_id" = ? AND "posts"."published" = 't' [["user_id", 1]]
Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."user_id" = ? AND "posts"."published" = 't' [["user_id", 2]]
Post Load (0.1ms) SELECT "posts".* FROM "posts" WHERE "posts"."user_id" = ? AND "posts"."published" = 't' [["user_id", 3]]
#=> [["Jack", "post-1, post-2"], ["Adam", "post-3, post-3"], ["John", "post-5, post-6"]]
User.includes(:posts).map do |user|
[user.name, user.posts.map(&:title).join(', ')]
end
User Load (0.2ms) SELECT "users".* FROM "users"
Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE "posts"."user_id" IN (1, 2, 3)
#=> [["Jack", "post-1, post-2"], ["Adam", "post-3, post-3"], ["John", "post-5, post-6"]]