Skip to content

Instantly share code, notes, and snippets.

View puncoz's full-sized avatar
🇳🇵
Working from home

Puncoz Nepal puncoz

🇳🇵
Working from home
View GitHub Profile
@puncoz
puncoz / php_helpers.php
Last active March 16, 2021 07:28
PHP Useful Helper functions
function _alphaOnly($value)
{
return preg_replace('/[^[:alnum:]\-\.]/u', '', $value);
}
/**
* @param $number
*
* @return string
*/
@puncoz
puncoz / deploy.rb
Created January 18, 2019 10:44 — forked from tjhanley/deploy.rb
Capistrano task for creating a change log file
desc "Create about and revision files."
task :rev_deployment, :roles => [:app, :web] do
require 'grit'
require 'chronic'
# include Grit
work_dir = File.join(File.dirname(__FILE__), '../../')
g = Grit::Repo.new(work_dir)
since = Chronic.parse('last week friday')
msg = "\n"
rev_file = File.join(File.dirname(__FILE__), '../../','tmp/revision.txt')
@puncoz
puncoz / responsive-text.js
Created January 7, 2019 08:57
Responsive Text, calculated font-size with respect to content wrapper.
export const responsiveText = (selector) => {
const rtWrappers = document.querySelectorAll(selector)
rtWrappers.forEach(wrapper => {
const width = wrapper.offsetWidth,
height = wrapper.offsetHeight,
text = wrapper.innerHTML
let textLength = typeof text === "string" ? text.trim().replace(" ", "").length : 0
@puncoz
puncoz / critical-css-laravel-mix.js
Created September 18, 2018 04:52 — forked from bayareawebpro/critical-css-laravel-mix.js
Generate Critical CSS Paths with Laravel Mix
let mix = require('laravel-mix');
let httpRequest = require('request')
let criticalCSS = require('critical')
//Run your asset compilation commands...
//Then we will generate critical css...
mix.then(()=>{
console.log("Build Post-Processing...")
const criticalRoutes = [
@puncoz
puncoz / js-helpers.js
Last active April 5, 2019 08:26
Some useful javascript helper functions.
export const kebabToPascalCase = str.replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => letter.toUpperCase()).replace(/[^\w]+/g, "");
// eg: some-string => SomeString
export const toNepaliNumber = n => (n + '').replace(/\d/g, i => '०१२३४५६७८९'[i])
export const numberToWord = amount => {
const a = ["", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen"];
const b = ["", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];
amount = (amount.toFixed(2)).toString().split(".");
@puncoz
puncoz / file.php
Created June 12, 2018 17:10 — forked from bainternet/file.php
a Simple class to convert number to words in php based on http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
<?php
//simple class to convert number to words in php based on http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
if ( !class_exists('NumbersToWords') ){
/**
* NumbersToWords
*/
class NumbersToWords{
public static $hyphen = '-';
public static $conjunction = ' and ';
@puncoz
puncoz / uniqid.php
Created May 13, 2018 05:20
alternative to uniqid() in php
function cryptoUniqid(string $prefix = '', bool $prng = false): string
{
static $nonce = null;
if($prng || is_null($nonce)) {
$nonce = random_bytes(16);
} else {
sodium_increment($nonce);
}
$m = microtime(true);
$return = sprintf("%8x%05x", floor($m), ($m-floor($m))*1000000);
@puncoz
puncoz / advance-nginx-config.md
Last active March 26, 2018 05:15
Advanced nginx configuration: Extra security & performance tuning. Original Source https://github.com/getgrav/grav/issues/1625

Advanced configuration for nginx

There are some small changes you can make to make your website faster, and a little more secure.

Security enhancements

The original configuration will keep you safe, but it is always good to see what else can be done.

Giving less information to attackers

By default, the nginx.conf will return "403 Forbidden" errors for system files that are not supposed to be accessed directly. However, there's a good alternative, like so:

@puncoz
puncoz / linux-command.md
Created January 14, 2018 15:21
Basic linux commands.
  1. To prints detailed information about all PCI buses and devices in the system
$ lspci

to get specific pci buses info

$ lspci | grep -i nvidia
@puncoz
puncoz / anaconda.md
Last active December 29, 2018 08:48
Anaconda Basic Commands for linux