Skip to content

Instantly share code, notes, and snippets.

View gbili's full-sized avatar

gbili gbili

View GitHub Profile
@gbili
gbili / git-reset-safe.sh
Created February 25, 2024 14:43
Prevent unintended git reset --hard
#!/bin/bash
# alias this script in your shell configuration file (e.g., .bashrc, .zshrc) with something like alias git='./git-reset-safe.sh', but ensure the script is in your PATH or use the full path to the script in the alias.
# Check if the first argument is 'reset' and the second is '--hard'
if [ "$1" = "reset" ] && [ "$2" = "--hard" ]; then
current_dir=$(pwd)
echo "🚨 About to nuke changes in: $current_dir"
echo "Paste the directory path to prove you're serious (no take-backs!):"
read user_input
@gbili
gbili / PI-Metal-Dectector.md
Created August 13, 2023 17:25
Pulse Induction (PI) metal detector

Creating a Pulse Induction (PI) metal detector is an exciting project that combines electronics and programming. Here's a step-by-step guide to help you build one:

1. Understand the Principle:

Pulse Induction metal detectors work by sending a short pulse of current through a coil of wire. After the pulse ends, the coil "listens" for the echo of the pulse. If there's a metal object nearby, it will induce a current in the object, which will then produce its own magnetic field. When this field collapses, it induces a small current in the coil, which can be detected.

2. Gather the Materials:

  • A coil of wire (for the search coil)
  • An oscillator (to create the pulse)
function print() {
const filename = 'ThisIsYourPDFFilename.pdf';
html2canvas(document.querySelector('#nodeToRenderAsPDF')).then(canvas => {
let pdf = new jsPDF('p', 'mm', 'a4');
pdf.addImage(canvas.toDataURL('image/png'), 'PNG', 0, 0, 211, 298);
pdf.save(filename);
});
}

Connect with PHP PDO

`$pdo = new \PDO('odbc:MYMSSQL', 'myusername', 'mypass'); $pdostmt = $pdo->prepare('SELECT TOP 10 FROM dbo.MyTableName'); if (!$pdostmt) { throw new Exception('There was an error'); } if (false === $pdostmt->execute()) { throw new Exception('The pdo statement did not execute successfully'); }

@gbili
gbili / gist:5503007
Last active December 16, 2015 21:50
this is the script that im trying to run
<?php
use Gbili\Miner\BluePrint,
Gbili\Miner\BluePrint\Action\Extract\Savable as ExtractSavable,
Gbili\Miner\BluePrint\Action\GetContents\Savable as GetContentsSavable,
Gbili\Vid\Savable\Lexer;
$a = array();//actions
$b = new BluePrint\Savable();
$b->setHost('myhost.com');
$b->setBasePath('./../');
@gbili
gbili / gist:5501490
Last active December 16, 2015 21:39
<?php
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$values = array_map(function($val) {
return "'".$val."'";
}, $this->values);
return "ENUM(".implode(", ", $values).") COMMENT '(DC2Type:".$this->name.")'";
}
@gbili
gbili / get active pages
Created April 6, 2013 14:49
Error argument to getActive($active->getChildren()) is NULL whereas $active->hasChildren() is true :/
<ul class="breadcrumb">
<?php
function getActive(array $level) {
$activeInLevel = array_filter($level, function ($page) {
return $page->isActive(true);
});
return $activeInLevel[0];
}?>
<?php $p = $this->pages ?>
<?php $active = getActive($p); echo get_class($active); ?>
@gbili
gbili / AbstractContainer
Created April 6, 2013 14:20
AbstractContainer Trying to get all the branch of the current active page (all parent pages too)
<?php
class Zend\Navigation\AbstractContainer
...
public function getActiveBranch()
{
$found = array();
@gbili
gbili / nav config
Last active December 15, 2015 21:29
navigation config array
<?php
return array(
'navigation' => array(
// The DefaultNavigationFactory we configured in (1) uses 'default' as the sitemap key
'default' => array(
// And finally, here is where we define our page hierarchy
'engine' => array(
'label' => 'Engine',
@gbili
gbili / bread
Created April 6, 2013 12:47
bread
<ul class="breadcrumb">
<?php $lastPageKey = count($this->pages) - 1?>
<?php var_dump($this->pages) //blank page?>
<?php foreach ($this->pages as $key => $page): // iterate through the pages?>
<li><?php get_class($pages) //error, expects object array given?></li>
<li>
<?php if ($key < $lastPageKey): // if this isn't the last page, add a link and the separator?>
<a href="<?= $page->getHref() ?>"><?= $page->getLabel() ?></a>
<span class="divider">/</span>
<?php else: // otherwise, just output the name ?>