Skip to content

Instantly share code, notes, and snippets.

BetterProgramming

Block or report user

Report or block BetterProgramming

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View restendpoints.java
@Path("/1.0/login")
@Produces("application/json")
public class LoginResource {
@POST
@Path("/")
Response login(@FormParam("username") String username,
@FormParam("password") String passowrd,
@HeaderParam("User-Agent") String userAgent) {
...
}
View SimplePojo.java
class SimplePojo {
private String name;
@JsonProperty(value = "json_name",
required = true,
access = ACCESS.READ_ONLY)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
View data.py
# Generate 5 rows x 5 columns
data = []
for x in range(5):
row = []
for y in range(5):
row.append(randint(0, 10))
data.append(row)
View MyAnnotatedType.java
Class<MyAnnotatedType> clazz = anInstance.getClass();
// or: Class<MyAnnotatedType> clazz = MyAnnotatedType.class;
// Target: Package
boolean isTypeAnnotationPresent =
clazz.getPackage().isAnnotationPresent(MyAnnotation.class);
// Target: Type
boolean isTypeAnnotationPresent =
clazz.isAnnotationPresent(MyAnnotation.class);
// Target: Method
Method method = clazz.getMethod("myMethod");
View Retention.java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Values {
String name() default "";
int value();
Class allowedTypes() default String.class,
ElementType[] types();
}
View Repeatable.java
public @interface MyRepeatableAnnotationContainer {
MyRepeatableAnnotation[] value();
}
@Repeatable(MyRepeatableAnnotationContainer.class)
public @interface MyRepeatableAnnotation {
String value() default "";
}
View MyAnnotation.java
// Both values are specified, naming them is required
@MyAnnotation(name = "an awesome name", value = 42)
public class MyType { ... }
// Only "value()" is present, "name()" will be its default value
@MyAnnotation(value = 42)
public class MyType2 { ... }
// Only "value()" needed, we can actually omit the name
@MyAnnotation(42)
public class MyType3 { ... }
View annotation.java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
public @interface MyAnnotation {
String name() default "";
int value();
}
View console.log.js
const log = () => {
console.log(x);
}
log();
let x = 1;
log();
View console.log.js
var x;
const log = () => {
console.log(x);
}
log();
x = 1;
log();
You can’t perform that action at this time.