Skip to content

Instantly share code, notes, and snippets.

@klaussilveira
klaussilveira / gist:1002961
Created June 1, 2011 18:34
Sorteio 4Linux
#!/usr/bin/php
<?php
if (isset($argv[1])) {
$lista = file($argv[1]);
$total = count($lista) - 1;
echo $lista[mt_rand(1, $total)];
} else {
echo "Passe uma lista de nomes como parâmetro!";
}
@klaussilveira
klaussilveira / gist:1004909
Created June 2, 2011 17:57
Symfony bootstrap
#!/bin/bash
if [ $1 ]
then
mkdir -p lib/vendor
wget http://www.symfony-project.org/get/symfony-1.4.13.tgz
tar -zxvf symfony-1.4.13.tgz
mv symfony-1.4.13 lib/vendor/symfony
rm symfony-1.4.13.tgz
php lib/vendor/symfony/data/bin/symfony generate:project $1
php symfony generate:app frontend
@klaussilveira
klaussilveira / gist:1189595
Created September 2, 2011 19:24
Branch verification inside Jenkins
#!/bin/bash
if [ "${GIT_BRANCH}" == "origin/master" ]
then
do stuff
else
do other stuff
fi
@klaussilveira
klaussilveira / gist:1391786
Created November 24, 2011 16:50
Github Suggestion Box
Github Suggestion Box
---------------------
Please, put your suggestions here. Octocat thanks you!
* Discussion module for each repository, allowing contributors and users to discuss various aspects of the repository
if ( $var == 'crazy' && $foo != 'bar' )
seems very unreadable for me.
@klaussilveira
klaussilveira / SDL.h
Last active September 19, 2019 20:02
PHP 7.4 FFI + SDL2
#define FFI_SCOPE "SDL"
#define FFI_LIB "libSDL2.so"
typedef uint8_t Uint8;
typedef uint16_t Uint16;
typedef uint32_t Uint32;
typedef uint64_t Uint64;
extern int SDL_Init(Uint32 flags);
extern int SDL_InitSubSystem(Uint32 flags);
<?php
require '../vendor/autoload.php';
$request = Symfony\Component\HttpFoundation\Request::createFromGlobals();
$context = (new Symfony\Component\Routing\RequestContext())->fromRequest($request);
$configLocator = new Symfony\Component\Config\FileLocator(__DIR__ . '/../config');
$file = '../var/cache/container.php';
if (\file_exists($file)) {
@klaussilveira
klaussilveira / hurricane.py
Created June 26, 2020 13:48
Check for hurricanes
import xml.etree.ElementTree as ET
import urllib.request
import re
namespaces = {'nhc': 'http://www.nhc.noaa.gov'}
# Drill: https://www.nhc.noaa.gov/rss_examples/index-at-20130605.xml
xml = urllib.request.urlopen('https://www.nhc.noaa.gov/index-at.xml').read()
root = ET.fromstring(xml)
hurricane = root[0].find('item/nhc:Cyclone', namespaces)
alter table books
add constraint books_doc_isbn_ok
check(
doc->>'ISBN' is not null and
jsonb_typeof(doc->'ISBN') = 'number' and
(doc->>'ISBN')::bigint > 0 and
length(doc->>'ISBN') = 13
);
@klaussilveira
klaussilveira / ExmpleSource.cpp
Created August 21, 2023 13:42 — forked from oldmanauz/ExmpleSource.cpp
Simple Flecs TD
/**
Copyright <2021> <Lexxicon Studios LLC.>
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.