Skip to content

Instantly share code, notes, and snippets.

View hgfernan's full-sized avatar

Hilton Fernandes hgfernan

  • S. Paulo, Brazil
  • 04:30 (UTC -12:00)
View GitHub Profile
@hgfernan
hgfernan / tpercent.py
Created May 15, 2017 01:33
A tiny test of sqlite3 in Python
"""
A example from Cinique LeNoir at Quora's question
https://codepad.co/snippet/XGfrziiE
Using the database schema
CREATE TABLE user_cats (save_directory VARCHAR(20), uploader VARCHAR(20), playlists VARCHAR(20));
"""
import sqlite3
@hgfernan
hgfernan / tIfSwitch.cpp
Created July 27, 2019 11:32
Comparison of an if-else nest with a switch case statement
#include <iostream>
#include <ctime>
#include <cstdlib>
#define HALFWAY ((0 + RAND_MAX) / 2)
int main()
{
int val;
/* From https://pt.stackoverflow.com/questions/516989/c%c3%b3digo-compila-mas-n%c3%a3o-funciona-apenas-finaliza-com-sucesso */
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *calculaPrimo(void *limitValue) {
int primo, j;
int num = 1;
int maxValue = *(int*)limitValue;
// From https://pt.stackoverflow.com/questions/516989/c%c3%b3digo-compila-mas-n%c3%a3o-funciona-apenas-finaliza-com-sucesso
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *calculaPrimo(void *limitValue) {
int primo, j;
int num = 1;
int maxValue = limitValue;
*** tThread_orig.c 2021-07-08 11:31:40.000795883 -0300
--- tThread.c 2021-07-08 11:49:00.032924787 -0300
***************
*** 1,4 ****
! // From https://pt.stackoverflow.com/questions/516989/c%c3%b3digo-compila-mas-n%c3%a3o-funciona-apenas-finaliza-com-sucesso
#include <stdio.h>
#include <stdlib.h>
--- 1,4 ----
! /* From https://pt.stackoverflow.com/questions/516989/c%c3%b3digo-compila-mas-n%c3%a3o-funciona-apenas-finaliza-com-sucesso */
@hgfernan
hgfernan / erroneous.cpp
Created July 16, 2021 15:38
Invalid C++ code, showing wrong attempt to access protected and private members.
#include <iostream>
class EncompassingClass {
class ProtectedClass;
static class PrivateClass {
private:
int privateMember;
PrivateClass() {
privateMember = 1;
}
@hgfernan
hgfernan / EncompassingClass.java
Created July 16, 2021 15:40
Valid Java code, showing no access limits to encompassed classes
/**
*
*/
package tPrivateProtected;
/**
* @author hilton
*
*/
public class EncompassingClass {
@hgfernan
hgfernan / IndependentPrivateClass.java
Last active July 16, 2021 15:49
Valid Java code showing a class accessing the protected member of another class in the same package that the former class is not not related by inheritance
/**
*
*/
package tPrivateProtected;
/**
* @author hilton
*
*/
public class IndependentPrivateClass {
@hgfernan
hgfernan / IndependentProtectedClass.java
Created July 16, 2021 15:49
Invalid Java code showing a class accessing the private member of another class in the same package
/**
*
*/
package tPrivateProtected;
/**
* @author hilton
*
*/
public class IndependentProtectedClass {
@hgfernan
hgfernan / bench.sh
Created March 3, 2022 19:50
Complementing a benchmark to evaluate JSON pretty printers.
export TEXT='{ "foo" : { "bar": { "dolorem" : "ipsum", "quia" : { "dolor" : "sit"} } } }'
function bench {
time (
for i in {1..100}; do
echo "${TEXT}" | $@ > /dev/null
done
)
}