Skip to content

Instantly share code, notes, and snippets.

View Summonshr's full-sized avatar

Suman Shrestha Summonshr

View GitHub Profile
@Summonshr
Summonshr / pre-commit-hook
Last active January 27, 2024 04:21
Modify pre commit message as per you require
#!/bin/bash
branch_name=$(git symbolic-ref --short HEAD) # Get the current branch name
short_branch_name=$(echo "$branch_name" | cut -c 1-8) # Extract the first 8 characters
# If the commit message file doesn't exist or is empty, use the default commit message
if [ ! -s "$1" ]; then
echo "$short_branch_name: " > "$1"
else
# Append the branch name to the beginning of the commit message
@Summonshr
Summonshr / App Service provider.php
Last active October 30, 2023 08:54
Laravel nova: hide error when input change
<?php
// Inside boot method
Nova::serving(function () {
Nova::script('input-error-handler-js', public_path('custom/js/nova.js'));
Nova::style('input-error-handler-css', public_path('custom/css/nova.css'));
});
@Summonshr
Summonshr / tweet.js
Last active July 16, 2023 16:53
Tweet automatically from nodejs script using openai and oauth1.0a
const axios = require('axios');
const util = require('util');
const crypto = require('crypto');
const OAuth = require('oauth-1.0a');
const options = [
'coding',
'music',
'sherlock holmes',
'wisdom',
String file contentssss
String file contents
@Summonshr
Summonshr / creating-vue-components-for-electron.js
Last active December 27, 2019 06:53
Had hard time implementing vue styles so created my own.
function component(name, url) {
let content = fs.readFileSync(url + '.vue', 'utf-8')
let element = document.createElement('body')
element.innerHTML = content
content = element.children[1].innerHTML.trim()
return Vue.component(name, {
template: element.children[0].innerHTML.trim(),
...eval('let module={};\n' + content)
})
}
@Summonshr
Summonshr / Question
Created February 7, 2019 09:16
Show how you can leverage Laravel Collections to create an elegant solution to the following problem. Create a function that accepts a GitHub username, and returns that users "Score" based on the below rules. The information can be retrieved using GitHub's public api
Show how you can leverage Laravel Collections to create an elegant solution to the following problem. Create a function that accepts a GitHub username, and returns that users "Score" based on the below rules. The information can be retrieved using GitHub's public api (https://api.github.com/users/:username/events/public). Upload your answer to a private gist (https://gist.github.com/) and share the URL.
PushEvent = 10 points.
PullRequestEvent = 5 points.
IssueCommentEvent = 4 points.
Any other event = 1 point
<?php
namespace App\Traits;
use App\Meta;
trait HasMeta
{
public function fromMeta($key)
{
return optional($this->meta->where('key', $key)->first())->value;