Skip to content

Instantly share code, notes, and snippets.

View nticaric's full-sized avatar

Nenad Ticaric nticaric

View GitHub Profile
@nticaric
nticaric / declared-but-not-used.go
Created July 25, 2020 19:48
declared but not used (as r-values)
package main
import (
"fmt"
)
func main() {
counter := 0
if shouldStartWithOne() {
@nticaric
nticaric / gist:99937096fa13bd78da7c67eb70c37c1b
Created July 25, 2020 19:47
declared but not used (as r-values)
package main
import (
"fmt"
)
func main() {
counter := 0
if shouldStartWithOne() {
@nticaric
nticaric / csvtosqlite.bash
Created June 5, 2018 12:16
Converting CSV to sqlite
# This example requires CSVkit (https://github.com/wireservice/csvkit). A Python toolset with a lot of very cool CSV tools.
# IMPORTANT NOTE: make sure to use a proper csv file. I had a lot of trouble with a csv file created by a service with Dutch
# as locale. Changing it to US solved the problem. Some locales use comma's to seperate point numbers. A semicolon is then
# used.
# Create table example and Load file-a.csv into it
csvsql --db sqlite:///example.db --table example --insert file-a.csv
# Add an extra file to table example
func backtrack(board *[9][9]int) bool {
if !hasEmptyCell(board) {
return true
}
for i := 0; i < 9; i++ {
for j := 0; j < 9; j++ {
if board[i][j] == 0 {
for candidate := 9; candidate >= 1; candidate-- {
board[i][j] = candidate
if isBoardValid(board) {
func isBoardValid(board *[9][9]int) bool {
//check duplicates by row
for row := 0; row < 9; row++ {
counter := [10]int{}
for col := 0; col < 9; col++ {
counter[board[row][col]]++
}
if hasDuplicates(counter) {
return false
func parseInput(input string) [9][9]int {
board := [9][9]int{}
scanner := bufio.NewScanner(strings.NewReader(input))
scanner.Split(bufio.ScanRunes)
for row := 0; row < 9; row++ {
for col := 0; col < 9; col++ {
scanner.Scan()
i1, _ := strconv.Atoi(scanner.Text())
func printBoard(board [9][9]int) {
fmt.Println("+-------+-------+-------+")
for row := 0; row < 9; row++ {
fmt.Print("| ")
for col := 0; col < 9; col++ {
if col == 3 || col == 6 {
fmt.Print("| ")
}
fmt.Printf("%d ", board[row][col])
if col == 8 {
@nticaric
nticaric / loadMNISTImages.php
Created November 10, 2016 21:53
A function that returns an array containing raw MNIST images
<?php
public function loadMNISTImages($filename)
{
$fp = fopen($filename, 'rb');
$array = unpack("N4", fread($fp, 16));
$magic = $array[1];
if($magic != 2051) {
@nticaric
nticaric / loadMNISTLabels.php
Last active November 10, 2016 21:52
A function that returns an array containing MNIST labels
<?php
public function loadMNISTLabels($filename)
{
$fp = fopen($filename, 'rb');
$array = unpack("N2", fread($fp, 8));
$magic = $array[1];
if($magic != 2049) {
<?php
public function processResults($res, $request)
{
$data = ['hits' => [], 'nbHits' => count($res)];
foreach ($res as $result) {
$file = file_get_contents($result['path']);
$crawler = new Crawler;
$crawler->addHtmlContent($file);