Skip to content

Instantly share code, notes, and snippets.

View jesobreira's full-sized avatar
💭
Implementing new bugs to fix later.

Jefrey Sobreira Santos jesobreira

💭
Implementing new bugs to fix later.
View GitHub Profile
@jesobreira
jesobreira / makeslug.js
Last active July 14, 2020 13:09
Create slugs with accented chars in PHP and Javascript
/*
* Javascript makeslug()
* by J. Santos <jefrey[at]jefrey[dot]ml>
*/
/*
Usage:
string makeslug( string val [, string replaceBy = "-" ] )
Example:
@jesobreira
jesobreira / gist:4e8b5e4a1fa2b32676de
Created July 5, 2015 15:11
CmdLine arguments parser (get values/existence/flags)
<?php
/*
Based on CmdLine UDF for AutoIt (also mine): https://www.autoitscript.com/forum/topic/169610-cmdline-udf-get-valueexistenceflag/
*/
class cmdline {
function get($sKey, $mDefault = Null) {
global $argv,$argc;
for($i = 1; $i <= ($argc-1); $i++) {
@jesobreira
jesobreira / example.php
Created August 1, 2015 06:40
Using bitwise operators to store privs
<?php
$user_rights = 3; // 1+2 (taken from database)
if(rights::can_read($user_rights)) echo "User can read\n";
if(rights::can_write($user_rights)) echo "User can write\n";
if(rights::can_modify($user_rights)) echo "User can modify\n";
class rights {
static $READ = 1;
@jesobreira
jesobreira / currency.js
Last active August 30, 2015 18:57
How to get currency using Javascript or PHP
/*
@author Jefrey S. Santos <github.com/jesobreira>
*/
function currency(icoin1, icoin2, value, callback) {
if(typeof value == 'undefined') value = 1;
icoin1 = icoin1.toUpperCase();
icoin2 = icoin2.toUpperCase();
value = parseFloat(value);
@jesobreira
jesobreira / rangeparser.au3
Last active January 12, 2016 19:33
Range
#cs
Range parser
This function parser printing-like intervals (like "1,2,3-5") and returns an array with every page number as item.
@author Jefrey S. Santos <jefrey[at]jefrey.ml>
#ce
Func rangeparser($interval)
$interval = StringReplace($interval, " ", "")
If Not StringRegExp($interval, "([0-9\-\,])") Then Return SetError(1, 0, False)
$interval = StringSplit($interval, ",")
@jesobreira
jesobreira / monitor.php
Last active October 25, 2023 13:26
Server Monitor
<?php
/*
The aim is to create a functional server monitor based on the one
showed on Mark Zuckerberg's monitor on The Social Network movie.
Run so:
php monitor.php
Notes:
- The server LogFormat must be "Common Log Format" (%h %^[%d:%^] "%r" %s %b)
@jesobreira
jesobreira / example.php
Last active May 1, 2016 15:46
PHP AutoIt-like INI file management
<?php
/*
All Ini-related functions from AutoIt are available.
Just add the paamayim nekudotayim (::) between "Ini" and the functio.
E.g.: IniWrite becomes Ini::Write, IniReadSectionNames becomes Ini::ReadSectionNames
Docs: https://www.autoitscript.com/autoit3/docs/functions/IniWrite.htm
*/
include 'phpini.class.php';
#include <Array.au3>
#Region Math
; http://sabemosdetudo.com/ciencias/ask67749-O_que_sao_numeros_relativamente_primos.html
Func RelativelyPrime($x, $y)
Return gdc($x, $y) = 1
EndFunc
; http://stackoverflow.com/a/21480873
Func gdc($a, $b)
@jesobreira
jesobreira / Example_ParseStr.au3
Created April 17, 2017 15:31
AutoIt ParseURL and ParseStr
#include <Array.au3> ; need only to do _ArrayDisplay, not needed by the lib
_ArrayDisplay(ParseStr("foo=bar&test=lol%20123"))
#cs
Result is:
[0][0] = 2
[0][1] = ununsed
[1][0] = foo
@jesobreira
jesobreira / sendgrid.php
Created February 6, 2018 20:14
Send email using Sendgrid (no lib or curl needed)
<?php
define('SENDGRID_KEY', 'SG.your api key here');
function sendgrid($from, $to, $subject, $message) {
$postdata = json_encode(
array(
'personalizations' => [
[
'to' => [