Skip to content

Instantly share code, notes, and snippets.

# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@antoni
antoni / gist:8160a3ce556b1724b984
Created February 10, 2016 18:59 — forked from osipov/gist:c2a34884a647c29765ed
Install Scala and SBT using apt-get on Ubuntu 14.04 or any Debian derivative using apt-get
sudo apt-get remove scala-library scala
sudo wget www.scala-lang.org/files/archive/scala-2.10.4.deb
sudo dpkg -i scala-2.10.4.deb
sudo apt-get update
sudo apt-get install scala
wget http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages/org/scala-sbt/sbt/0.12.4/sbt.deb
sudo dpkg -i sbt.deb
sudo apt-get update
sudo apt-get install sbt
@antoni
antoni / catch.hpp
Created January 28, 2016 11:26
Single-header Catch (framework for unit-tests, TDD and BDD)
/*
* Catch v1.3.3
* Generated: 2016-01-22 07:51:36.661106
* ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
@antoni
antoni / FastIO.java
Created January 25, 2016 12:56
Fast I/O in Java
import java.io.*;
import java.util.InputMismatchException;
/**
* Created by Shreyans on $DATE at $TIME using IntelliJ IDEA (Fast IO Template)
*/
class $NAME
{
public static void main(String[] args) throws Exception
@antoni
antoni / ReflectionInvoke.java
Last active December 13, 2015 22:05
Invoke a Java method when given the method name as a string
// Get the method
try {
java.lang.reflect.Method method = obj.getClass().getMethod(methodName, param1.class, param2.class, ..);
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
// Invoke the method
@antoni
antoni / c_timing.c
Created December 4, 2015 12:49
Timing C code
#include <time.h>
#include <stdio.h>
#include <stdint.h>
inline uint64_t rdtsc() {
uint32_t lo, hi;
__asm__ __volatile__ (
"xorl %%eax, %%eax\n"
"cpuid\n"
@antoni
antoni / AcademicDegree.java
Last active December 27, 2024 13:49
Random enum value in Java
public enum AcademicDegree {
DEGREE_MSC, DEGREE_PHD, DEGREE_PHD_HAB, DEGREE_PROF;
private static final AcademicDegree[] VALUES = values();
private static final int SIZE = VALUES.length;
private static final Random RANDOM = new Random();
public static AcademicDegree getRandomLetter() {
return VALUES[RANDOM.nextInt(SIZE)];
@antoni
antoni / FileLineReader.java
Last active October 30, 2015 10:16
Different ways of reading file line by line in Java (Java 8 on the bottom)
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
@antoni
antoni / error_handling.cu
Last active September 24, 2015 15:22
Error handling in CUDA
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
@antoni
antoni / hide_keystrokes.c
Created September 17, 2015 11:21
Hide & show keystrokes in a Linux terminal
#include <termios.h>
void hide_keystrokes() {
struct termios tty;
tcgetattr(STDIN_FILENO, &tty);
tty.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &tty);
}
void show_keystrokes() {