Skip to content

Instantly share code, notes, and snippets.

@Jyang772
Jyang772 / gist:5648314
Created May 25, 2013 07:55
Card simulator
deck=matrix(c(rep( c(2:10,"J","Q","K","A"),4),rep(c("C","D","H","S"),rep(13,4))), ncol=2,dimnames=list(NULL,c("rank","suit")))
deal_hand = function()
{
return( deck[sample(1:52,5,replace=F),])
}
what_hand = function(hand)
{
@Jyang772
Jyang772 / InlineASM.cpp
Created April 15, 2014 05:41
Inline Assembly
#include <stdio.h>
int get_shrek()
{
asm(".intel_syntax noprefix\n"
"mov eax, 42 \n");
}
int main()
{
@Jyang772
Jyang772 / Toggle.cpp
Last active August 29, 2015 14:01
Toggle
#include <iostream>
using namespace std;
int main()
{
int toggle;
int counter=1; //remember to initialize this. otherwise junk or null. Most likely junk/garbage...GG.
for(int i = 1; i<= 12; i++)
{
@Jyang772
Jyang772 / hash.cpp
Last active August 29, 2015 14:01
UnHash me
#include <iostream>
using namespace std;
int main()
{
char array[] = "acdegilmnoprstuw";
string result;
long long h = 910897038977002;
for(int i=0; i <9;i++)
for(int j=0; j <16;j++)
@Jyang772
Jyang772 / gist:12c11b4863c06a83bbc9
Created January 15, 2015 07:23
Changing Audio/Input Devices
#List audio sinks
pacmd list-sinks
#Change default from monitor to USB (0 --> 1)
pacmd set-default-sink 1
#Get all input streams
pacmd list-sink-inputs
#Move input stream from ex. 5 to 1
pizza=$(echo "xxx yyy
xxx yyy" | awk '{ if($2 == "yyy") print $2}')
Awk tries to match pattern in every line. Then outputs $2 to variable 'pizza', concatenating the entries.
#!/bin/sh
module="TITS"
device="TITS"
if ! [[ -z "$1" ]]; then
ps aux | grep $1 | awk {'print $2'} | xargs kill -9
else
echo "Not set"
fi
/* free block with user-pointer p (block actually starts at p - TAGSIZE) */
void freef(char *p)
{
/* you write the code for the freef function here */
printf("freef called with p=%p\n", (void *) p);
if(p < allocbuf || p > allocbuf + ALLOCSIZE) {
printf("freef: BAD POINTER!, %p\n", (void*)p);
return;
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class 3Sum
{
static HashSet<int[]> res = new HashSet<int[]>();
public static void main (String[] args) throws java.lang.Exception
https://cdn-images-1.medium.com/max/660/1*WgROsTKa6diRYTG5K0R5mw.jpeg
http://scruss.com/wordpress/wp-content/uploads/2013/06/random20130606210630.png
https://upload.wikimedia.org/wikipedia/commons/thumb/3/36/Two_red_dice_01.svg/220px-Two_red_dice_01.svg.png
https://cdn-images-1.medium.com/max/1600/1*t_G1kZwKv0p2arQCgYG7IQ.gif
https://vignette.wikia.nocookie.net/austinally/images/1/14/Random_picture_of_shark.png/revision/latest?cb=20150911004230
http://www.lozano-hemmer.com/image_sets/method_random/method_random2.jpg
https://openclipart.org/download/232694/Pattern20a.svg
https://i.pinimg.com/originals/f5/9b/1b/f59b1b0cc430702e82dea90780d7f87d.gif
https://cdn.dribbble.com/users/815278/screenshots/2375130/random-turtle.gif
https://media.boingboing.net/wp-content/uploads/2016/08/pandyland.jpg