This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Scheduler { | |
public static void main(String[] args) { | |
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); | |
final Runnable ticker = new Runnable() { | |
public void run() { | |
System.out.println("Ran"); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new FileReader("PATH1")); | |
int T = Integer.parseInt(br.readLine()); | |
PrintWriter writer = new PrintWriter("PATH2", "UTF-8"); | |
writer.println("Line"); | |
writer.close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Utils { | |
public static long mulmod(long a, long b, long mod) { | |
return (a * b) % mod; | |
} | |
public static long binpow(long a, long pow, long mod) { | |
if (pow == 0) | |
return 1; | |
long res = binpow(a, pow / 2, mod); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To join list of srings on a delimiter | |
List<String> l = new ArrayList<>(); | |
String.join("+", l); | |
// To split based on control character | |
String[] strings = br.readLine().split("\\+"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ascii_int = (int) 'a'; | |
char ascii_char = (char) 97; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/perl | |
use strict; | |
use warnings; | |
use AnyEvent; | |
use AnyEvent::Handle; | |
use Parallel::SubFork; | |
my $manager = Parallel::SubFork->new(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collections.sort(list, new Comparator<Pair>() { | |
public int compare(Pair p1, Pair p2) { | |
//Reverse order of i (integers) and lexicographic order of s (strings) | |
return p1.i < p2.i ? 1 : p1.i > p2.i ? -1 : p1.s.compareTo(p2.s); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Parallel::SubFork; | |
use Data::Dumper; | |
my $manager = Parallel::SubFork->new(); | |
for(1..10) { | |
$manager->start(\&cb, [$_]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Data::Dumper; | |
use AnyEvent::Handle; | |
use AnyEvent; | |
my($pipe_w, $pipe_r); | |
pipe $pipe_r, $pipe_w; | |
my $cv = AnyEvent->condvar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use POSIX qw( WNOHANG ); | |
my $spawn_processes = 5; | |
my $forked = 0; | |
my ($err, $success) = (0, 0); | |
my $local_id = 0; | |
print "($$) parent has started\n"; |
NewerOlder