Skip to content

Instantly share code, notes, and snippets.

View ghalusa's full-sized avatar
🤓
Geekin'

Goran Halusa ghalusa

🤓
Geekin'
View GitHub Profile
@SpacePossum
SpacePossum / matches.twig
Last active December 19, 2023 13:25
Example how Twig `(not) matches` works
{% set foo = '123' %}
{{ foo matches '/^[\\d]+$/' ? 'Y' : 'N' }}
{{ foo matches not '/^[\\d]+$/' ? 'Y' : 'N' }} {# wrong, does not work! #}
{{ not (foo matches '/^[\\d]+$/') ? 'Y' : 'N' }}
{% set foo = 'abc' %}
{{ foo matches '/^[\\d]+$/' ? 'Y' : 'N' }}
{{ foo matches not '/^[\\d]+$/' ? 'Y' : 'N' }} {# wrong, does not work! #}
{{ not (foo matches '/^[\\d]+$/') ? 'Y' : 'N' }}
@kottenator
kottenator / simple-pagination.js
Created July 13, 2015 20:44
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@MikeRogers0
MikeRogers0 / resize-image.js
Last active September 17, 2019 12:07
An example of how to resize an image on the fly with javascript.
// The function that scales an images with canvas then runs a callback.
function scaleImage(url, width, height, liElm, callback){
var img = new Image(),
width = width,
height = height,
callback;
// When the images is loaded, resize it in canvas.
img.onload = function(){
var canvas = document.createElement("canvas"),
@psdtohtml5
psdtohtml5 / gist:5646810
Created May 24, 2013 22:03
PHP: Secure File Download
<?php
// PHP SECURE FILE DOWNLOAD
// Put the Files in a directory that is not publically accessible.. maybe outside document root or set correct permissions
if (!$_SESSION["authenticated"]) {
// If not authenticated then send back to the login page
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/login.php?err=true");
exit;
@RodrigoAyala
RodrigoAyala / nodejs_installer.sh
Created March 24, 2013 01:49
Bash script to install NodeJS on the Raspberry Pi
#!/bin/bash
echo -e "nodejs_installer.sh - \033[37mNode\033[32m\033[32mJS \033[0minstaller for \033[35mRaspberry Pi\033[0m"
echo -e "========================================================\n"
if [ "$(uname -m)" != "armv6l" ]; then
echo -e "\033[31mError: \033[0marmv6l architecture not found. (Are you sure that you are running the script on a Raspberry Pi?)\033[0m";
exit 1;
else
echo -e "\033[35mRaspberry Pi \033[32mfound! Proceeding...\033[0m"
@desandro
desandro / require-js-discussion.md
Created January 31, 2013 20:26
Can you help me understand the benefit of require.js?

I'm having trouble understanding the benefit of require.js. Can you help me out? I imagine other developers have a similar interest.

From Require.js - Why AMD:

The AMD format comes from wanting a module format that was better than today's "write a bunch of script tags with implicit dependencies that you have to manually order"

I don't quite understand why this methodology is so bad. The difficult part is that you have to manually order dependencies. But the benefit is that you don't have an additional layer of abstraction.


@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',
@csanz
csanz / slideshow.js
Created April 24, 2012 19:27
intro to node.js slide show app written in node.js
var color = require('colors');
var stdin = process.openStdin()
, slides = {
1: "\tNode.js" +
"\n\n\t\tJavascript running on the server" +
"\n\n\t\tWritten in C++ (POSIX)" +
"\n\n\t\tWraps V8 JS VM (Google/Chrome)"
, 2: "\tOthers / Evented I/O" +
"\n\n\t\t > Reactor Pattern" +
"\n\n\t\t > EventMachine(Ruby) / Twisted (Python)" +
@natestarner
natestarner / Nodejs Instructions
Created March 8, 2012 05:50
Complete Nodejs Environment Setup
The objective of this post is to get you from absolutely nothing, to a fully functional nodejs environment.
Software used: Ubuntu 11.10, Nodejs v0.6.12, Nginx, MongoDB, Redis, and NPM modules.
1. Download and install the latest version of Ubuntu: http://www.ubuntu.com/download (don't select any extra items to install when prompted)
2. Once you are logged in and are at your Ubuntu command prompt, install the necessary software you will need:
a. sudo apt-get install openssh-server
b. sudo apt-get install libssl-dev
c. sudo apt-get install git
d. sudo apt-get install g++
e. sudo apt-get install make
@ziadoz
ziadoz / awesome-php.md
Last active May 10, 2024 15:06
Awesome PHP — A curated list of amazingly awesome PHP libraries, resources and shiny things.